

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solution script for MatLab example
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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) !!!!
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