You are on page 1of 5

Problem 3A

EDU>> type HW4Problem3


A=[5 4 4 4; 5 6 5 5; 6 6 7 6; 7 7 7 8];
b=[17; 21; 25; 29];
[n,n]=size(A);
for k=1:n
L(k,k)=1;
for i=k+1:n
L(i,k)=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j);
end
end
for j=k:n
U(k,j)=A(k,j);
end
end
Lb=[L b];
[m,s]=size(Lb);
g=Lb(:,s);
for i=1:m
for j=1:i-1
g(i)=g(i)-L(i,j)*g(j);
end
g(i)=g(i)/L(i,i);
end
Ug=[U g];
[h,p]=size(Ug);
x=Ug(:,p);
for i=p-1:-1:1
for j=i+1:p-1
x(i)=x(i)-Ug(i,j)*x(j);
end
x(i)=x(i)/Ug(i,i);
end
x
EDU>> run HW4Problem3
x=
1.0000
1.0000
1.0000

1.0000
Problem 3B
EDU>> type HW4Problem3
A=[5 7.1429 6 5; 7 10 8 7; 6 8 9 9; 5 7 9 7];
b=[1; -1; -1; 1];
[n,n]=size(A);
for k=1:n
L(k,k)=1;
for i=k+1:n
L(i,k)=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j);
end
end
for j=k:n
U(k,j)=A(k,j);
end
end
Lb=[L b];
[m,s]=size(Lb);
g=Lb(:,s);
for i=1:m
for j=1:i-1
g(i)=g(i)-L(i,j)*g(j);
end
g(i)=g(i)/L(i,i);
end
Ug=[U g];
[h,p]=size(Ug);
x=Ug(:,p);
for i=p-1:-1:1
for j=i+1:p-1
x(i)=x(i)-Ug(i,j)*x(j);
end
x(i)=x(i)/Ug(i,i);
end
x
EDU>> run HW4Problem3
x=
60.8718

-39.2459
6.0059
-11.8130
Problem 3C
EDU>> type HW4Problem3
A=[14 14 -9 3 -5; 14 52 -15 2 -32; -9 -15 36 -5 16; 3 2 -5 47 49; -5 -32 16 49 79];
b=[-15; -100; 106; 329; 463];
[n,n]=size(A);
for k=1:n
L(k,k)=1;
for i=k+1:n
L(i,k)=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j);
end
end
for j=k:n
U(k,j)=A(k,j);
end
end
Lb=[L b];
[m,s]=size(Lb);
g=Lb(:,s);
for i=1:m
for j=1:i-1
g(i)=g(i)-L(i,j)*g(j);
end
g(i)=g(i)/L(i,i);
end
Ug=[U g];
[h,p]=size(Ug);
x=Ug(:,p);
for i=p-1:-1:1
for j=i+1:p-1
x(i)=x(i)-Ug(i,j)*x(j);
end
x(i)=x(i)/Ug(i,i);
end
x
EDU>> run HW4Problem3
x=

-0.0000
1.0000
2.0000
3.0000
4.0000
Problem 3D
EDU>> type HW4Problem3
A=[3 -5 6 4 -2 -3 8; 1 1 -9 15 1 -9 2; 2 -1 5 5 -1 6 11; -1 1 5 2 3 -1 -2; 4 3 1 -7 2 5 1; 2 9 -8 11 -1
-4 -1; 7 2 -1 2 7 -1 9];
b=[47; 17; 24; 8; 13; -10; 34];
[n,n]=size(A);
for k=1:n
L(k,k)=1;
for i=k+1:n
L(i,k)=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j);
end
end
for j=k:n
U(k,j)=A(k,j);
end
end
Lb=[L b];
[m,s]=size(Lb);
g=Lb(:,s);
for i=1:m
for j=1:i-1
g(i)=g(i)-L(i,j)*g(j);
end
g(i)=g(i)/L(i,i);
end
Ug=[U g];
[h,p]=size(Ug);
x=Ug(:,p);
for i=p-1:-1:1
for j=i+1:p-1
x(i)=x(i)-Ug(i,j)*x(j);
end
x(i)=x(i)/Ug(i,i);
end
x

EDU>> run HW4Problem3


x=
12.9596
-7.0573
1.8334
4.6633
0.5910
3.5191
-5.6349