Você está na página 1de 10

%

,;

ans

You can have more than one


statement on a single line by
separating each statement with
commas or semicolons
If you don't assign a variable to
store the result of an operation,
the result is stored in a
temporary variable called ans

a = [1 2 3 4 6 4 3 4 5]

a=

b=a+2

1
2
4
5
b=
3
6

plot(b)
grid on
bar(b)
xlabel('Sample #')
ylabel('Pounds')
plot(b,'*')
axis([0 10 0 10])
A = [1 2 0; 2 5 -1; 4 10
-1]

B = A'

C=A*B

X = inv(A)

I = inv(A) * A

C = A .* B

*****

semicolons (;) to separate the


rows of a matrix

A=

multiply these two matrices


together

variety of other symbols and


line types

transpose of the matrix A

1
2
4
B=

2
0
5 -1
10 -1

1
2
0
C=

2
5
-1

4
10
-1

inverse of a matrix

5 12 24
12 30 59
24 59 117
X=
2
-1
-2

-2
1
1

identity matrix

5
-2
0
I=
1
0
0
C=

0
1
0

0
0
1

multiply the corresponding


elements of two matrices or

vectors using the .* operator

eig(A)

svd(A)

p = round(poly(A))

roots(p)

q = conv(p,p)

obtain eigenvalues

1
4
0
4 25 -10
0 -10
1
ans =

singular value decomposition

3.7321
0.2679
1.0000
ans =

The "poly" function generates a


vector containing the
coefficients of the characteristic
polynomial.
The characteristic polynomial of
a matrix A is det (I-A)

12.3171
0.5149
0.1577
p=
1

-5

the roots of a polynomial

ans =

To convolve two vectors

3.7321
1.0000
0.2679
q=
1 -10

r = conv(p,q)
plot(r);

convolve again and plot the


result

-1

35 -52

35 -10

1
r=
1 -15 90 -278 480 -480
278 -90 15 -1

whos

At any time, we can get a


listing of the variables we have
stored in memory using the
who or whos command.

Name
Size
Attributes

value of a particular variable by


typing its name

A=

A
B
C
I
X
a
ans
b
p
q
r

Bytes Class

3x3
3x3
3x3
3x3
3x3
1x9
3x1
1x9
1x4
1x7
1x10

72 double
72 double
72 double
72 double
72 double
72 double
24 double
72 double
32 double
56 double
80 double

1
2
0
2
5 -1
4 10 -1
ans =

sqrt(-1)

0 + 1.0000i
A = magic(3)

creating a magic square and


assigning it to the variable A

A=
8
3

1
5

6
7

B = 2*ones(3)

4
B=

2
2
2

A.*B

2
2
2
2
2
2
ans =
16
2
6 10
8 18
oooo

12
14
4

plot(Y,'ro')
title('Title name)
n=length(Y)
hold on
hold of
t = (1900:10:2000)'

multiply each element of A with


its corresponding element of B
by using the .* operator

Red circle

Ten step interval


t=
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000

Legend()
stem(A)
axis square
axis of
axis on
axis equal
det(A)
trace(A)
poly(A)

Description inside graph


Plot the result in in vertical lines
Of axis
Equal size axis
Matrix determinant
Sum of diagonal elements
Polynomial with specified roots

=
1.0000 -15.0000 -18.0000
-0.0000

sqrtm(A)
A = pascal(3)

Matrix square root


A=
1
1
1
ans =

rand(3,3)

1
2
3

0.6771
0.5198
0.0768
chol(A)

1
3
6

0.0558
0.2587
0.4399

Cholesky Factorization
1
0
0

1
1
0

1
2
1

0.2843
0.6788
0.9496

[V,D] = eig(A)

V=
-0.5438 -0.8165
0.7812 -0.4082
-0.3065 0.4082

0.1938
0.4722
0.8599

D=
0.1270
0
0
0 1.0000
0
0
0 7.8730

GRAPHICS
x = [0:.2:20];

y=

y = sin(x)./sqrt(x+1);
y(2,:) =
sin(x/2)./sqrt(x+1);
y(3,:) = sin(x/3)./sqrt(x+1)

Columns 1 through 10
0.1814
0.0911
0.0608

Você também pode gostar