Parte 3 Jercicio 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

a)

function x=gauss(a, b)

ab = [a,b];

[m, n] = size(ab);

for j = 1:m-1

for i = j+1:m

ab(i,j:n) = ab(i,j:n)-ab(i,j)/ab(j,j)*ab(j,j:n);

end

end

x = zeros(m,1);

x(m) = ab(m,n)/ab(m,m);

for i = m-1:-1:1

x(i)=(ab(i,n)-ab(i,i+1:m)*x(i+1:m))/ab(i,i);

end

endfunction

b)

AUM = [A b]

X = AUM

[rX cX] = size(X)

//Eliminación hacia adelante

for p = 1 : 1 : rX-1 //Fila del pivote

pivote = X(p,p);

for i = p + 1 : 1 : rX //Fila a procesar

prim_fila = X(i,p)

X(i,:) = X(i,:) - (X(p, :)/pivote)*prim_fila

end

end

x(rX) = X(rX, cX)/X(rX, cX - 1)

for i = rX : -1 : 1
s=0

PARTE 3. EJERCICIO 2

function [L U]=LU(A)
[m,n]=size(A) ; %A tiene m filas y n columnas
L=eye(m); %L tiene unos en la diagonal
for k=1:n
for i=k+1:m
L(i,k)=A(i,k)/A(k,k) %elemento pivote
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j); %operacion por filas
end
end
end
L;
U=triu(A);

COMMAND WINDOW

A= [10 2 -1 27;-3 -6 -2 -61.5;1 1 5 -21.5]

A=

10.0000 2.0000 -1.0000 27.0000

-3.0000 -6.0000 -2.0000 -61.5000

1.0000 1.0000 5.0000 -21.5000

>> [L U]=LU(A)

L=

1.0000 0 0

-0.3000 1.0000 0

0 0 1.0000
L=

1.0000 0 0

-0.3000 1.0000 0

0.1000 0 1.0000

L=

1.0000 0 0

-0.3000 1.0000 0

0.1000 -0.1481 1.0000

L=

1.0000 0 0

-0.3000 1.0000 0

0.1000 -0.1481 1.0000

U=

10.0000 2.0000 -1.0000 27.0000

0 -5.4000 -2.3000 -53.4000

0 0 4.7593 -32.1111
INVERSA

>> A = [10 2 -1;-3 -6 -2;1 1 5]

A=

10 2 -1

-3 -6 -2

1 1 5

>> B = [27;-61.5;-21.5]

B=

27.0000

-61.5000

-21.5000

>> inv(A)*B

ans =

-0.5272

12.7626

-6.7471

Entonces tenemos que:

>> X=-0.5272

>> Y= 12.7626

>> Z= -6.7471
>> inv(A)

ans =

0.1089 0.0428 0.0389

-0.0506 -0.1984 -0.0895

-0.0117 0.0311 0.2101

>> A*inv(A)

ans =

1.0000 0.0000 -0.0000

0.0000 1.0000 -0.0000

0 0.0000 1.0000

You might also like