-

Help Variable

-
Matlab
Matrix
Laboratory
http://www.mathworks.com/


command

windows

workspace :
command





history


help

>> doc sqrt
>> help sqrt
Help icon.
Variable

>> x=1
x=
1
>> x=1;

◦ ans : default variable name for the result
◦ pi:  = 3.1415926…………
◦ Inf or inf : , infinity
◦ NaN or nan: not-a-number

◦ clear.
◦ clear all
◦ clc.






>> 3+3
ans =
6
>>14/2
ans =
7
>>13.4-6
ans =
7.4000

>> 14/2 , 5*6 , 1+1.2
ans=
7
ans =
30
ans =
2.2000
------------------------------->>3*2+1
>>3*(2+1)
------------------>> 5+3i
ans =
5.0000 + 3.0000i
>> (3+4i)+(1+i)
ans =
4.0000 + 5.0000i
• >>Save mywork.mat
• >>load mywork.mat
>> 1/(2+3^2)+4/5*6/7
ans =
0.7766
•diag(A)
•Size(A)
•Length(A)



Matrixname(m,n) 
n
m

ones(m,n)
zeros(m,n)
eye(m,n)
the main diagonal
Example:
>> f = [ 1 2 3; 4 5 6];
>> h= [ 2 4 6; 1 3 5];
>> f(2,3)
f=
1
ans =
4
6
h=
2
>> h(:,1)
1
ans =

2
1

2
5

3
6

4
3

6
5
a=[6 8]/2
a=
3
4

-

a=[1 2;3 4]^2
a=
7 10
15 22

-

a=[1 2] + [3 4]
a=
[4 6]
—
a=[3 4]-[1 2]
a=
[2 2]

-

a=[1 2;3 4]*[3;6]
a=
15
33

-

-
a=[1 2;3 4].^2
a=
1
4
9 16

>> a=[1 2 3;4 5 6]'
a=
1
2
3

4
5
6
Example:
>> A=[1 2 3;4 5 6];
>> A>3
ans =
0
0
0
1
1
1
>> A<=5
ans =
1
1
1
1
1
0
>> x=[0 0 0 1];
>> x&1
ans =
0
0
0
1
>> x|1
ans =
1
1
1
1



True

1

False

0

AND

&

OR

|

NOT

~


Example: a system of 3 linear equations
with 3 unknowns (x1, x2, x3):

3x1 + 2x2 + x3 = 10
-x1 + 3x2 + 2x3 = 5
x1 – x2 – x3 = -1

3 2 1
 1 3 2 
A


 1  1  1



 x1 
x 
x   2
 x3 
 
Ax = b

10 
5
b
 
 1
 
>> A=[3 2 1;-1 3 2;1 -1 -1];
>> b=[10;5;-1];
>> inv(A)*b

ans =
2.0000
1.0000
2.0000

 x1 
x 
 2
 x3 
 


A = [3 4 4 3 ; 4 5 6 7 ; 5 6 7 4 ; 4 5 6 7]






الجلسة الأولى

الجلسة الأولى