Question: Challenge - 1 Built - in functions MATLAB provides numerous built - in variables and functions. For each line below, type the text in the

Challenge-1 Built-in functions
MATLAB provides numerous built-in variables and functions. For each line below, type the
text in the Command Window and press to see what happens. Is the result what you
expect? Fill in the blanks below with the screen output for that line.
% Variables, constants, and simple calculations:
a=250% Look at the Workspace Pane: a VARIABLE called a has been created
a=901% Look at the variables value in the Workspace Pane
b=89
a/b %_____________________________
ans
y= ans %_____________________________
x =2;
y = x^x; z = y^y %_____________________________
% Built-in functions:
sqrt(x)
pi % a built-in variable
cos(pi)%_____________________________
abs(ans)
abs(cos(pi))%_____________________________
exp(ans)
mod(7,2)%_____________________________ Function rem is similar
help mod % quick function reference
help rem
doc rem % detailed function documentation
b=(4*2)...
+1% What does ... do?_____________________________
% Its called the ellipsis
Challenge-2 for-loop
A for-loop repeats the loop bodythe statements between the loop header and the end
keyworda pre-determined number of times. (The loop header is the line that begins with
the keyword for). What does each loop below do? Write in each blank the output from
executing the loop above.
for a =2:1:6
disp(a)%___________________________________
end
for b =2:6
disp(b)%___________________________________
end
for c =12:0.5:14
disp(c)%___________________________________
CT248: Introduction to Modelling
Assignment-1
end
for d =0:-2:-6
disp(d)%___________________________________
end
for f =0:-2:-7
disp(f)%___________________________________
end
for g =5:2:1
disp(g)% How many times does the loop body execute? ________
end % Any error message? ________
Challenge-3 Vectors
a= zeros(1,3)%________________
b= ones(3,1)%________________ What do the arguments specify?______________________
c= rand(1,4)%________________
d=10:2:17%________________
f=10:-1:7%________________
g=10:2:0%________________
h=[102040]%________________ What does the space separator do?___________________
m=[10,20,40]%________________ What does the comma separator do?___________________
n=[10;20;40]%________________ What does the semi-colon separator do?______________
p=[a h]%________________
q=[b; n]%________________
r=[a n]% ERROR--mismatched dimensions! (Attempt to concatenate a column to
% a row)
s= b'%________________ This operation is called "transpose"
t=[a b']%________________
u= sum(t)%________________ What does function sum do?__________________________
CT248: Introduction to Modelling
Assignment-1
Challenge-4 Determinant of a 3x3 matrix
Write MATLAB code, where x is a 3x3 matrix. Use the following formula:
Use the built-in function det() to find the determinant of each 2\times 2 matrix. For
example, det(m) returns the determinant of 2\times 2 matrix m. Then use the formula given above
to calculate the determinant of a 3\times 3 matrix. This question is all about practicing how to access
individual components or submatrices in a matrix. Recall that you can construct a matrix by
putting two row vectors one below the other or putting two column vectors side by side.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!