Professional Documents
Culture Documents
L03-Matlab Introduction
L03-Matlab Introduction
L03-Matlab Introduction
>> 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(2)
produces
a
2
by
2
matrix
of
zeros.
ans
=
0 0
0 0
>>
zeros(1,3)
zeros(1,3)
produces
a
1
by
3
matrix
of
zeros.
ans
=
0 0 0
>>
A
=
eye(3)
eye(3)
produces
a
3
by
3
iden#ty
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 =
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 =
5
Op#miza#on
in
Prac#ce
with
MATLAB:
20
for
Engineering
Students
and
Professionals
The
current
directory
is
generally
displayed
in
a
text
box
towards
the
top
of
the
MATLAB
screen.
Alterna#vely,
you
can
type
pwd
at
the
command
prompt
to
display
the
current
directory.
while EXPRESSION
STATEMENTS
end
expression.
>>
x=2
switch
x
case
1
disp('x
is
equal
to
1')
case
2
disp('x
is
equal
to
2')
end
x
=
2
x
is
equal
to
2
>> myMFile
My first output