L01 Matlab Introduction
L01 Matlab Introduction
Course Name
Lecture - 1
>> a_long_variable = 2;
>> another_long_variable = 3;
>> x = a_long_variable + a_long_variable^2 ...
+ another_long_variable
x=
9
ans =
ones(3) produces a 3 by 3 matrix of ones.
1 1 1
1 1 1
1 1 1
1 1 1
>> zeros(2)
zeros(3) produces a 2 by 2 matrix of zeros.
ans =
0 0
0 0
>> zeros(1,3)
zeros(1,3) produces a 1 by 2 matrix of zeros.
ans =
0 0 0
>> A = eye(3)
eye(3) produces a 3 by 3 identity matrix.
A=
1 0 0
0 1 0
0 0 1
>> v=[1;1;1]
v=
1
1
1
>> A*v
ans =
9
18
a=
2 3 4 5 6 7 8
>> 1:2:9
ans =
1 3 5 7 9
>> 50:-5:30
ans =
50 45 40 35 30
>> P=[1 2 3 4 ; 5 6 7 8]
P=
1 2 3 4
5 6 7 8
pp =
6 7 8
>> x = 2
x=
y=
8.0822
z=
1.0259
>> complex_number = 4 + 3i
complex_number =
4.0000 + 3.0000i
magnitude =
while EXPRESSION
STATEMENTS
end
if EXPRESSION
STATEMENTS
else
STATEMENTS
end
>> x=2
switch x
case 1
disp('x is equal to 1')
case 2
disp('x is equal to 2')
end
x=
x is equal to 2
>> myMFile
My first output
global x