Professional Documents
Culture Documents
Script:!
%%%%11.13!
format long!
A=[2 -6 -1; -3 -1 7; -8 2 -2]!
b=[-38; -34; -20]!
x_1=0.000000001;!
x_2=0;!
x_3=0;!
x_test=1;!
n=0;!
error=1;!
while error>0.05!
x_test=x_1;!
x_1=(b(1,1)-A(1,2)*x_2-A(1,3)*x_3)/A(1,1);!
x_2=(b(2,1)-A(2,1)*x_1-A(2,3)*x_3)/A(2,2);!
x_3=(b(3,1)-A(3,1)*x_1-A(3,2)*x_2)/A(3,3);!
error=abs(x_1-x_test)/(x_1)*100;!
n=n+1;!
end!
x=[x_1;x_2;x_3]!
error!
!
!
while error>0.05!
x_test=x_1;!
x_1old=x_1;!
x_1=(b(1,1)-A(1,2)*x_2-A(1,3)*x_3)/A(1,1);!
x_1=lambda*x_1+(1-lambda)*x_1old;!
x_2old=x_2;!
x_2=(b(2,1)-A(2,1)*x_1-A(2,3)*x_3)/A(2,2);!
x_2=lambda*x_2+(1-lambda)*x_2old;!
x_3old=x_3;!
x_3=(b(3,1)-A(3,1)*x_1-A(3,2)*x_2)/A(3,3);!
x_3=lambda*x_3+(1-lambda)*x_3old;!
error=abs(x_1-x_test)/(x_1)*100;!
n=n+1;!
end!
x_lambda=[x_1;x_2;x_3]!
error=error!
!
A =!
!
2
-3
-8
!
!
b =!
!
-6
-1
2
-1!
7!
-2!
-38!
-34!
-20!
!
!
x =!
!
-19!
91!
177!
!
error =!
!
-1.000000000052632e+02!
!
!
lambda =!
!
1.200000000000000!
!
!
x_lambda =!
!
1.0e+02 *!
!
-0.228000000002000!
1.228800000007200!
2.688960000018240!
!
error =!
!
-1.000000000043860e+02!
2)!
Script:!
%%%%%%%%%11.18!
A=[4 3 2;1 3 1;2 1 3];!
b=[960;510;610];!
Ab=[A b];!
Ab(1,:)=Ab(1,:)-Ab(2,:);!
Ab(3,:)=Ab(3,:)+Ab(2,:);!
Ab(3,:)=Ab(3,:)-Ab(1,:);!
Ab(2,:)=Ab(2,:)-(3/4)*Ab(3,:);!
Ab(2,:)=Ab(2,:)+(5/4)*Ab(1,:);!
Ab(2,:)=2*Ab(2,:);!
Ab(1,:)=Ab(1,:)-(30/95)*Ab(2,:);!
Ab(3,:)=Ab(3,:)-3*Ab(1,:);!
Ab(2,:)=Ab(2,:)/Ab(2,1);!
Ab(3,:)=0.25*Ab(3,:)!
transistors=Ab(2,4)!
resistors=Ab(3,4)!
computer_chips=Ab(1,4)!
disp('This solution was obtained using Gaussian Elimination, but had to be modified slightly
because the solution of the system could only consist of positive integers)!
!
Ab =!
!
!
0
1
0
0
0
1
1 90!
0 120!
0 100!
transistors =!
120!
resistors =!
100!
!
!
computer_chips =!
90!
This solution was obtained using Gaussian Elimination, but had to be modified slightly because
the solution of the system could only consist of positive integers!
3)!
!
function [ A_I ] = ident( A )!
!
A_I=[A eye(size(A))]!
end!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
4)!
Script:!
%%%%%%%%%%%%%%%%%%12.13!
format long!
A=[0.52 0.20 0.25;.30 .50 .20; .18 .30 .55]!
b=[4800;5800;5700]!
Ab=[A b]!
x_1=0.000000001;!
x_2=0;!
x_3=0;!
x_test=1;!
n=0;!
error=1;!
while error>0.005!
x_test=x_1!
x_1=(b(1,1)-A(1,2)*x_2-A(1,3)*x_3)/A(1,1);!
x_2=(b(2,1)-A(2,1)*x_1-A(2,3)*x_3)/A(2,2);!
x_3=(b(3,1)-A(3,1)*x_1-A(3,2)*x_2)/A(3,3);!
error=abs(x_1-x_test)/(x_1)*100;!
n=n+1;!
end!
x=[x_1;x_2;x_3];!
error!
pit_1=x_1!
pit_2=x_2!
pit_3=x_3!
pits=[pit_1;pit_2;pit_3]!
actual=A*pits!
for i=1:3!
error_volume=abs(actual(i,1)-b(i,1))/b(i,1)*100!
end!
!
disp('Each error value corresponds to sand, fine and coarse gravel, respectively')!
!
!
Command Window:!
!
>> p12_13!
!
A =!
!
0.520000000000000 0.200000000000000 0.250000000000000!
!
!
b =!
!
4800!
5800!
5700!
!
!
Ab =!
!
1.0e+03 *!
!
!
!
vol_per_pit =!
!
1.0e+03 *!
!
4.005768832426005!
7.131471025742541!
5.162764186255558!
!
!
actual_sand_fine_coarse =!
!
1.0e+03 *!
!
4.799985044573920!
5.800018999850184!
5.700000000000000!
!
!
error_volume =!
!
3.115713766608981e-04!
!
!
error_volume =!
!
3.275836238572083e-04!
!
!
error_volume =!
!
!
0!
Each error value corresponds to sand, fine and coarse gravel, respectively!
>>