You are on page 1of 2

>> A=[1 -1 1 0;-1 2 -1 0;1 -1 5 2;0 2 2 6]

A=

1 -1 1 0
-1 2 -1 0
1 -1 5 2
0 2 2 6

>> E1=eye(4);E1(2,1)=-A(2,1)/A(1,1);A1=E1*A

A1 =

1 -1 1 0
0 1 0 0
1 -1 5 2
0 2 2 6

>> E2=eye(4);E2(3,1)=-A(3,1)/A(1,1);A2=E2*A1

A2 =

1 -1 1 0
0 1 0 0
0 0 4 2
0 2 2 6

>> %PIVOTEO
>> E3=eye(4);E3([2 4],:)=E3([4 2],:);A3=E3*A2

A3 =

1 -1 1 0
0 2 2 6
0 0 4 2
0 1 0 0

>> E4=eye(4);E4(4,2)=-A3(4,2)/A3(2,2);A4=E4*A3

A4 =

1 -1 1 0
0 2 2 6
0 0 4 2
0 0 -1 -3

>> E5=eye(5);E5(4,3)=-A4(4,3)(A4(3,3);A5=E5*A4
E5=eye(5);E5(4,3)=-A4(4,3)(A4(3,3);A5=E5*A4

Error: Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for
mismatched delimiters.
Did you mean:
>> E5=eye(5);E5(4,3)=-A4(4,3)/A4(3,3);A5=E5*A4
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix
matches the number
of rows in the second matrix. To perform elementwise multiplication, use '.*'.

>> E5=eye(4);E5(4,3)=-A4(4,3)/A4(3,3);A5=E5*A4

A5 =

1.0000 -1.0000 1.0000 0


0 2.0000 2.0000 6.0000
0 0 4.0000 2.0000
0 0 0 -2.5000

>> U=A5;P=E3

P=

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

>> L=P*inv(E5*E4*E3*E2*E1)

L=

1.0000 0 0 0
0 1.0000 0 0
1.0000 0 1.0000 0
-1.0000 0.5000 -0.2500 1.0000

>> %A=P-1*L*U-A
>> %COMPROBACION
>> inv(P)*L*U-A

ans =

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

You might also like