Solution script to MatLab example, Exercises of Matlab skills

Solution script for MatLab example

Typology: Exercises

2020/2021

Uploaded on 07/30/2024

kaelyn-smith-1
kaelyn-smith-1 🇺🇸

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
First Script
%%%%%%%%%% Kaelyn Smith 1/20/22 %%%%%%%%%%
% first test - variable assignment
h = 10;
h = h+1;
% runs from top to bottom; wouldn't be able to switch (variable undefined)
% don't have to assign data type; still need to define variable (value)
% semicolon prevents display/printing of line of code
% basic operations / displaying
a = 2;
b = 3;
sum = a + b;
disp("the sum is: " + sum)
the sum is: 5
%second test - variable assignment
p = 3;
q = 4;
r = (p^2 + q^2)^0.5;
% underline = when smnthg may be wrong / off -> r is used twice
% reassigning values
% since r is NOT a function (it's an assignment) so MatLab will not update
p = 6;
q = 8;
%to update values, retype equation
r = (p^2 +q^2)^0.5
r = 10
% bonus points for organized code (aka add commments) !!!!
% INBUILT FUNCTIONS %
x = 3; y = 4;
% if using semicolons, can keep code on same line
c = sqrt(x^2 + y^2)
c = 5
% sqrt = function name (built into MatLab) - see lecture day 2 notes
% cubed root of 27
d = nthroot(27, 3)
d = 3
1
pf2

Partial preview of the text

Download Solution script to MatLab example and more Exercises Matlab skills in PDF only on Docsity!

First Script

%%%%%%%%%% Kaelyn Smith 1/20/22 %%%%%%%%%%

% first test - variable assignment h = 10; h = h+1; % runs from top to bottom; wouldn't be able to switch (variable undefined) % don't have to assign data type; still need to define variable (value) % semicolon prevents display/printing of line of code

% basic operations / displaying a = 2; b = 3; sum = a + b; disp("the sum is: " + sum)

the sum is: 5

%second test - variable assignment p = 3; q = 4; r = (p^2 + q^2)^0.5; % underline = when smnthg may be wrong / off -> r is used twice

% reassigning values % since r is NOT a function (it's an assignment) so MatLab will not update p = 6; q = 8; %to update values, retype equation r = (p^2 +q^2)^0.

r = 10

% bonus points for organized code (aka add commments) !!!!

% INBUILT FUNCTIONS %

x = 3; y = 4; % if using semicolons, can keep code on same line c = sqrt(x^2 + y^2)

c = 5

% sqrt = function name (built into MatLab) - see lecture day 2 notes

% cubed root of 27 d = nthroot(27, 3)

d = 3

% log of 1 e = log(1)

e = 0

% natural log of 10 f = log10(10)

f = 1