Operaciones Con Matrices Y Vectores
Operaciones Con Matrices Y Vectores
>> A=[1 2 3; 4
A=
1
4
7
2
5
8
3
6
9
4
5
6
7
8
9
>> A'
ans =
1
2
3
>> B=A'
B=
1
2
3
4
5
6
>> B*A
7
8
9
5 6; 7 8 9]
ans =
66 78 90
78 93 108
90 108 126
>> A=[1 4 -3; 2 1 5; -2 5 3]
A=
1
2
-2
4
1
5
-3
5
3
>> B=inv(A)
B=
0.1803
0.1311
-0.0984
0.2213 -0.1885
0.0246 0.0902
0.1066 0.0574
>> B*A
ans =
1.0000 0.0000 -0.0000
0 1.0000 0.0000
0 -0.0000 1.0000
>> x=[10 20 30] % vector fila
x=
10
20
30
x=
1 2
OPERADORES ARITMTICOS
>> A=[1 2; 3 4]
A=
1
2
3
4
>> A*2
ans =
2
6
4
8
>> A-4
ans =
-3
-1
-2
0
TIPOS DE DATOS
>> 1.0/0.0
ans =
Inf
>> 0/0
ans =
NaN
>> inf/inf
ans =
NaN
3 13
10
8
6 12
15
1
>> j=A>10
j=
1
0
0
0
0
1
0
1
0
0
0
1
1
0
1
0
>> isa(j,'logical')
ans =
1
>> A(j)=-10
A=
-10
2
3 -10
5 -10 10
8
9
7
6 -10
4 -10 -10
1
i=
2
>> 2+3i
ans =
2.0000 + 3.0000i
>> 2+3*i
ans =
8
>> 2+3*j
ans =
2.0000 + 3.0000i
>> A = [1+2i 2+3i; -1+i 2-3i]
A=
1.0000 + 2.0000i 2.0000 + 3.0000i
1.0000
2.0000 - 3.0000i
>> A = [1 2; -1 2] + [2 3; 1 -3]*i % En este caso el * es necesario
A=
5
1
8
-4
>> complex(1,2)
ans =
1.1
+ 2.0000i
0.2420
0.9757
0.3172
>> B=diag(diag(A))
0.8128
0.6974
0.2695
B=
0.9040
0
0
0 0.9757
0
0
0 0.2695
>> C=[A, eye(3); zeros(3), B]
C=
0.9040
0.9409
0.8025
0
0
0
>> x=1:10
x=
1
10
>> x=1:2:10
x=
1
>> x=1:1.5:10
x=
1.0000
2.5000
4.0000
5.5000
7.0000
>> x=10:-1:1
x=
10
>> x=[0.0:pi/50:2*pi]';
>> y=sin(x); z=cos(x);
>> [x y z]
ans =
0
0.0628
0.1257
0.1885
0.2513
0.3142
0 1.0000
0.0628 0.9980
0.1253 0.9921
0.1874 0.9823
0.2487 0.9686
0.3090 0.9511
8.5000 10.0000
0.3770
0.4398
0.5027
0.5655
0.6283
0.6912
0.7540
0.8168
0.8796
0.9425
1.0053
1.0681
1.1310
1.1938
1.2566
1.3195
1.3823
1.4451
1.5080
1.5708
1.6336
1.6965
1.7593
1.8221
1.8850
1.9478
2.0106
2.0735
2.1363
2.1991
2.2619
2.3248
2.3876
2.4504
2.5133
2.5761
2.6389
2.7018
2.7646
2.8274
2.8903
2.9531
3.0159
3.0788
3.1416
3.2044
3.2673
3.3301
3.3929
3.4558
3.5186
3.5814
3.6442
3.7071
0.3681
0.4258
0.4818
0.5358
0.5878
0.6374
0.6845
0.7290
0.7705
0.8090
0.8443
0.8763
0.9048
0.9298
0.9511
0.9686
0.9823
0.9921
0.9980
1.0000
0.9980
0.9921
0.9823
0.9686
0.9511
0.9298
0.9048
0.8763
0.8443
0.8090
0.7705
0.7290
0.6845
0.6374
0.5878
0.5358
0.4818
0.4258
0.3681
0.3090
0.2487
0.1874
0.1253
0.0628
0.0000
-0.0628
-0.1253
-0.1874
-0.2487
-0.3090
-0.3681
-0.4258
-0.4818
-0.5358
0.9298
0.9048
0.8763
0.8443
0.8090
0.7705
0.7290
0.6845
0.6374
0.5878
0.5358
0.4818
0.4258
0.3681
0.3090
0.2487
0.1874
0.1253
0.0628
-0.0000
-0.0628
-0.1253
-0.1874
-0.2487
-0.3090
-0.3681
-0.4258
-0.4818
-0.5358
-0.5878
-0.6374
-0.6845
-0.7290
-0.7705
-0.8090
-0.8443
-0.8763
-0.9048
-0.9298
-0.9511
-0.9686
-0.9823
-0.9921
-0.9980
-1.0000
-0.9980
-0.9921
-0.9823
-0.9686
-0.9511
-0.9298
-0.9048
-0.8763
-0.8443
3.7699
3.8327
3.8956
3.9584
4.0212
4.0841
4.1469
4.2097
4.2726
4.3354
4.3982
4.4611
4.5239
4.5867
4.6496
4.7124
4.7752
4.8381
4.9009
4.9637
5.0265
5.0894
5.1522
5.2150
5.2779
5.3407
5.4035
5.4664
5.5292
5.5920
5.6549
5.7177
5.7805
5.8434
5.9062
5.9690
6.0319
6.0947
6.1575
6.2204
6.2832
-0.5878
-0.6374
-0.6845
-0.7290
-0.7705
-0.8090
-0.8443
-0.8763
-0.9048
-0.9298
-0.9511
-0.9686
-0.9823
-0.9921
-0.9980
-1.0000
-0.9980
-0.9921
-0.9823
-0.9686
-0.9511
-0.9298
-0.9048
-0.8763
-0.8443
-0.8090
-0.7705
-0.7290
-0.6845
-0.6374
-0.5878
-0.5358
-0.4818
-0.4258
-0.3681
-0.3090
-0.2487
-0.1874
-0.1253
-0.0628
-0.0000
-0.8090
-0.7705
-0.7290
-0.6845
-0.6374
-0.5878
-0.5358
-0.4818
-0.4258
-0.3681
-0.3090
-0.2487
-0.1874
-0.1253
-0.0628
-0.0000
0.0628
0.1253
0.1874
0.2487
0.3090
0.3681
0.4258
0.4818
0.5358
0.5878
0.6374
0.6845
0.7290
0.7705
0.8090
0.8443
0.8763
0.9048
0.9298
0.9511
0.9686
0.9823
0.9921
0.9980
1.0000
>> A=magic(6)
A=
35
1
3 32
31
9
8 28
30
5
4 36
>> A(2,3)
6 26 19 24
7 21 23 25
2 22 27 20
33 17 10 15
34 12 14 16
29 13 18 11
ans =
7
>> A(6, 1:4)
ans =
4
36
29
13
>> A(3, :)
ans =
31
22
27
20
>> A(end, :)
ans =
4
36
29
13
18
11
>> A(3:5,:)
ans =
31
9
8 28
30
5
2 22 27 20
33 17 10 15
34 12 14 16
6 26 19 24
7 21 23 25
34 12 14 16
>> B=eye(size(A));
>> B([2 4 5],:)=A(1:3,:)
B=
1
0
35
1
0
0
3 32
31
9
0
0
0
6
1
7
2
0
0
0
0
26 19 24
0
0
0
21 23 25
22 27 20
0
0
1
>> B=eye(size(A));
>> B(1:2,:)=[0 1; 1 0]*B(1:2,:)
B=
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
>> x=rand(1,5)
x=
0.5896
0.8330
0.3638
0.7098
0.3383
0.3638
0.8330
0.5896
>> x=x(5:-1:1)
x=
0.3383
0.7098
>> A=magic(3)
A=
8
3
4
1
5
9
6
7
2
>> A(:,3:-1:1)
ans =
6
7
2
1
5
9
8
3
4
1
5
9
>> B=[]
B=
[]
>> exist(B)
6
7
2
ans =
0
>> isempty(B)
ans =
1
>> A(:,3)=[]
A=
8
3
4
1
5
9
real(x)
imag(x)
abs(x)
angle(x)
partes reales
partes imaginarias
valores absolutos
ngulos de fase
>> A=magic(3)
A=
8
3
4
1
5
9
6
7
2
>> M=A>4
M=
1
0
0
0
1
1
1
1
0
>> A=magic(3)
A=
8
3
4
1
5
9
6
7
2
>> m=find(A>4)
m=
1
5
6
7
8
>> A(m)=10*ones(size(m))
A=
10
1
3 10
4 10
10
10
2
>> any(A==3)
ans =
1
>> any(ans)
ans =
1
>> all(all(A))
ans =
1
>> x=[1 2 3 4 0/0 6]
x=
1
4 NaN
>> i=find(isnan(x))
i=
5
>> x=x(find(~isnan(x)))
x=
1
>> x=x(~isnan(x))
x=
1
>> x(isnan(x))=[]
x=
1
10
10
2
pol =
1
-8
6 -10
>> roots(pol)
ans =
-3.2800
2.6748
0.3026 + 1.0238i
0.3026 - 1.0238i
>> polyval(pol,1)
ans =
-11
>> pol1=[1 -2 4]
pol1 =
1
-2
-4
>> pol3=conv(pol1,pol2)
pol3 =
1 -2
7 -10 20 -16
>> syms x
>> y=sin(x); z=cos(x);
>> simplify(y^2+z^2)
ans =
1
>> limit(sin(x)/x,0)
ans =
1
>> syms n
>> limit((n^3+3*n^2-2*n)/(3*n^3-1),inf)
ans =
1/3
>> f='exp(z^3)+sin(z)^2'
f=
exp(z^3)+sin(z)^2
>> diff(f)
ans =
2*cos(z)*sin(z) + 3*z^2*exp(z^3)
>> f='a*exp(a+x)/sin(a*x)'
f=
a*exp(a+x)/sin(a*x)
>> diff(f,'a')
ans =
exp(a + x)/sin(a*x) + (a*exp(a + x))/sin(a*x) - (a*x*exp(a +
x)*cos(a*x))/sin(a*x)^2
>> pretty(ans)
exp(a + x) a exp(a + x) a x exp(a + x) cos(a x)
---------- + ------------ - ----------------------sin(a x)
sin(a x)
2
sin(a x)
>> f='a*exp(a*x)';
>> int(f,'x')
ans =
exp(a*x)
>> int(f,'x',0,1)
ans =
exp(a) - 1
>> int('exp(x^2)','x',0,1)
ans =
-(pi^(1/2)*erf(i)*i)/2
>> f=inline('exp(x.^2)');
>> quad(f,0,1)
ans =
1.4627
>>
quad('x.*exp(x)',0,1)
ans =
1.0000
GRFICOS
BIDIMENSIONALES
>> x=[1 3 2 4 5 3]
x=
1
>> plot(x)
>> x=0:pi/25:6*pi;
>> y=sin(x); z=cos(x);
>> plot(x,y,x,z)
>>
z=eig(rand(20,20));
>> plot(real(z),imag(z),'+')
>> x=[-
4*pi:pi/20:4*pi];
>> plot(x,sin(x),'r',x,cos(x),'g')
>> title('Funcin seno(x) -en rojo- y funcin coseno(x) -en verde-')
>> xlabel('ngulo en radianes'), figure(gcf)
>> ylabel('valor de la funcin trigonomtrica'), figure(gcf)
>> axis([-12,12,-1.5,1.5]), figure(gcf)
>> axis('equal'), figure(gcf)
>> axis('normal'), figure(gcf)
>> axis('square'), figure(gcf)
>>
>>
>>
>>
>>
>>
>>
>>
x=[rand(1,100)*10];
plot(x)
bar(x)
stairs(x)
hist(x)
hist(x,20)
alfa=(rand(1,20)-0.5)*2*pi;
rose(alfa)