You are on page 1of 12

UNIVERSIDAD DE AYACUCHO FEDERICO FROEBEL

FACULTAD DE CIENCIAS TECNOLGICAS E INGENIERA


ESCUELA DE INGENIERA DE SISTEMAS Y TECNOLOGA

MATRICES

CURSO : METODOS NUMERICOS


PROFESOR : MONCADA SOSA Wilmer Enrique
CICLO : IV
ALUMNO : ALMEYDA CARPIO, Erika
MARMANILLO SALCEDO, Eyner J.
VEGA MACEDO, Zidane D.
YACE HUAMAN, Javier

AYACUCHO-PER
2017
Ejercicios de Matlab matrices

1)
a= [1,2,3;0,1,4;3,0,2]
b= [4,1,2;3,2,1;0,1,2]

c=a+b
d=a-b
e=a*b

c=
5 3 5
3 3 5
3 1 4
d=
-3 1 1
-3 -1 3
3 -1 0
e=
10 8 10
3 6 9
12 5 10

2)
a= [1,2,3;0,1,4;3,0,2]

b= [4,1,2;3,2,1;0,1,2]

y=b'*a'
d=(a*b)'

y=
10 3 12
8 6 5
10 9 10
d=
10 3 12
8 6 5
10 9 10
3)
a= [1,2,3;0,1,4;3,0,2]

b= [3;5;1]

e=a*b

e=

16
9
11

4)
a= [1,2,3,1;0,1,4,2;3,0,2,3]

b= [4,1,2;3,2,1;0,1,2;3,1,0]

c= [7;1;4]

e= [2,3,0,1;0,1,0,1;2,1,5,0]

d=a+e
i=a-e
f=a*b
g=b*a
h=b*c

d=

3 5 3 2
0 2 4 3
5 1 7 3

i=

-1 -1 3 0
0 0 4 1
1 -1 -3 3

f=

13 9 10
9 8 9
21 8 10

g=

10 9 20 12
6 8 19 10
6 1 8 8
3 7 13 5

h=

37
27
9
22
5)
b= [3,2,1;0,4,3;0,0,6]
c= [1,0,2; -1,1,0;0,3,2]
d= [1,0,0; -2,1,0;5,2,7]

e=b+(c*d)

e=

14 6 15
-3 5 3
4 7 20

6)
Clear

a= [2 1 -3 -1; -1 3 2 12; 3 1 -3 0]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x

a=

-1.0000 3.0000 2.0000 12.0000


0 10.0000 3.0000 36.0000
0 0 -1.1000 -2.2000

x=

1.0000
3.0000
2.0000

Clear

a= [0.1 -0.6 1 0; -2 8 0.3 1; 1 6 4 2;]


x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x
a=

-2.0000 8.0000 0.3000 1.0000


0 10.0000 4.1500 2.5000
0 0 1.0980 0.1000

x=

0.3625
0.2122
0.0911

7)
Clear

a= [4 1 -1 9; 3 2 -6 -2; 1 -5 3 1;]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x

a=

3.0000 2.0000 -6.0000 -2.0000


0 -5.6667 5.0000 1.6667
0 0 5.5294 11.1765

x=

2.3830
1.4894
2.0213

Clear

a= [1 1 0 0; -1 2 -1 1; 0 -1 1.1 0;]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x

a=

-1.0000 2.0000 -1.0000 1.0000


0 -1.0000 1.1000 0
0 0 2.3000 1.0000

x=

-0.4783
0.4783
0.4348

8)
Clear

a= [1 1 1 1; 2 -1 3 4; 3 2 -2 -2;]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x

a=

2.0000 -1.0000 3.0000 4.0000


0 3.5000 -6.5000 -8.0000
0 0 2.2857 2.4286

x=

0.2500
-0.3125
1.0625

Clear

a= [1 1 1 -2; 2 -1 3 5; 3 2 -2 1;]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x
a=

2.0000 -1.0000 3.0000 5.0000


0 3.5000 -6.5000 -6.5000
0 0 2.2857 -1.7143

x=

2.0000
-3.2500
-0.7500

Clear

a= [1 1 1 2; 2 -1 3 -1; 3 2 -2 4;]
x= [0,0,0]';
tempo=a (2, :); a (2, :) = a (1, :); a (1, :)=tempo; a
a (2, :)=a (2, :) - a (1, :)*a (2,1) /a (1,1);
a (3, :)=a (3, :) - a (1, :)*a (3,1) /a (1,1); a
tempo=a (3, :); a (3, :)= a (2, :); a (2, :)=tempo; a
a (3, :) = a (3, :)-a (2, :)*a (3,2) /a (2,2); a
x (3) = a (3,4) /a (3,3);
x (2) = (a (2,4)-a (2,3) *x (3)) /a (2,2);
x (1) = (a (1,4)-a (1,2:3) *x (2:3)) /a (1,1); x

a=

2.0000 -1.0000 3.0000 -1.0000


0 3.5000 -6.5000 5.5000
0 0 2.2857 0.1429

x=

0.2500
1.6875
0.0625

9)
a= [7,1;4,5]

inv(a)
y=a*a^-1

inv =

0.1613 -0.0323
-0.1290 0.2258

y=
1.0000 0
0 1.0000

10)
a= [1,-1,0,0; -1,2,-1,0;0,-1,2,-1;0,0,-1,2]
b= [1,4,5;2,1,2;8,1,1]

inv(a)

inv(b)

ans =

4 3 2 1
3 3 2 1
2 2 2 1
1 1 1 1
ans =

-0.0400 0.0400 0.1200


0.5600 -1.5600 0.3200
-0.2400 1.2400 -0.2800

11)
m= [3,1,0;1,2,1;0,1,1]

inv(m)

ans =

0.5000 -0.5000 0.5000


-0.5000 1.5000 -1.5000
0.5000 -1.5000 2.5000

12)
m= [0,5,1; -1,6,3;3,-9,5]

inv(m)

ans =

0.9344 -0.5574 0.1475


0.2295 -0.0492 -0.0164
-0.1475 0.2459 0.0820

13)
a= [2,-1,0; -1,2,-1;;0,-1,2]

[l, u]=lu(a)

l=

1.0000 0 0
-0.5000 1.0000 0
0 -0.6667 1.0000

u=

2.0000 -1.0000 0
0 1.5000 -1.0000
0 0 1.3333

a= [2,-1,0; -3,4,-1;0,-1,2]
[l, u]=lu(a)

l=

-0.6667 1.0000 0
1.0000 0 0
0 -0.6000 1.0000

u=

-3.0000 4.0000 -1.0000


0 1.6667 -0.6667
0 0 1.6000

15)

a= [1,4;3,2]

det(a)

ans =

-10

b= [3,2;1,3]

det(b)

ans =

c= [4,-1,2;1,2,-3;0,3,1]

det(c)

ans =

51

d= [-1,1,2,-3;2,-1,3,2;0,2,4,1;5,1,1,-1]

det(d)

ans =

-199.0000

16)
a= [8,2,1,1;1,9,3,0;3,-1,2,6;2,-2,-1,4]

det(a)

ans =

740.0000
[l, u, p]=lu(a)

l=

1.0000 0 0 0
0.1250 1.0000 0 0
0.3750 -0.2000 1.0000 0
0.2500 -0.2857 -0.1948 1.0000

u=

8.0000 2.0000 1.0000 1.0000


0 8.7500 2.8750 -0.1250
0 0 2.2000 5.6000
0 0 0 4.8052

p=

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

17)
a= [1,2,3;4,5,6;7,8,9]

inv(a)

[l, u, p]=lu(a)

ans =

1.0e+16 *

0.3153 -0.6305 0.3153


-0.6305 1.2610 -0.6305
0.3153 -0.6305 0.3153

l=

1.0000 0 0
0.1429 1.0000 0
0.5714 0.5000 1.0000

u=

7.0000 8.0000 9.0000


0 0.8571 1.7143
0 0 -0.0000

p=

0 0 1
1 0 0
0 1 0

18)
b= [3,2,1;0,4,3;0,0,6]

c= [1,0,2; -1,1,0;0,3,2]

d= [1,0,0; -2,1,0;5,2,7]

a=b*c*d

a^-1

a=

31 21 56
0 25 42
24 42 84

ans =

-0.1667 -0.2917 0.2569


-0.5000 -0.6250 0.6458
0.2976 0.3958 -0.3844

19)
a'

det(a)

det(a')

ans =

31 0 24
21 25 42
56 42 84

ans =

-2.0160e+03

ans =

-2.0160e+03

21)
Clear

a(1,1) = 1/2 + 1/4 + 1/3; a(1,2) = -1/4; a(1,3) = -1/3;


a(2,1) = a(1,2); a(2,2) = 1/4 + 1/3 + 1/5; a(2,3) = -1/5;
a(3,1) = a(1,3); a(3,2) = a(2,3); a(3,3) = 1/3 + 1/5 + 1/3;
y(1) = 20/2; y(2) = 0; y(3) = 5/3;
x = zeros (x, x);
w=1.2;
for elem = 1:50
error = 0;
for i=1:3
s=0; xb = x(i);
for j=1:3
if i~=j, s=s+a (i, j)*x(j); end
end
x(i) = w*(y(i)-s)/a(i,i) + (1-w)*x(i);
error = error +abs (x(i) - xb);
end
fprintf (' Elem.nm. = %3.0f, error = %7.2e\n',elem , error)
if error/3 < 0.0001, break; end
end
x

23)
syms s

A= [2-s, 4, 6; 1, -1-s, 5; 2, 0, 1-s]

det(A)

A=

[ 2 - s, 4, 6]
[ 1, - s - 1, 5]
[ 2, 0, 1 - s]

ans =

- s^3 + 2*s^2 + 17*s + 46

VALOR DE S

A= [-1 2 17 46]

r=roots (A)

r=

6.0589 + 0.0000i
-2.0294 + 1.8638i
-2.0294 - 1.8638i