Saturday, April 28, 2012

11.15

Of the following three sets of linear equations, identify the set(s) that you could not solve using an iterative method such as Gauss-seidel. Show using any number of iterations that is necessary that your solution does not converge. Clearly state your convergence criteria (how you know it is not converging).



set one
9x + 3y +z = 13
-6x + 8z =2
2x +5y -z = 6




set two
x +y +6z = 8
x+ 5y - z = 5
4x + 2y - 2z = 4

set three
-3x +4y +5z = 6
-2x +2y -4z = -3
2y -z = 1



Matlab code:


A = [9 3 1; -6 0 8; 2 5 -1];
B = [13; 2; 6];

solution1 = A \ B;
x = [0 0 0];
for ii = 1:100
    x(1) = (B(1) - A(1,2) * x(2) - A(1,3) * x(3))/A(1,1);
    x(2) = (B(2) - A(2,1) * x(1) - A(2,3) * x(3))/A(2,2);
    x(3) = (B(3) - A(3,1) * x(1) - A(3,2) * x(2))/A(3,3);
end

display(solution1);
display(x);

%set two

A = [1 1 6; 1 5 -1; 4 2 -2];
B = [8;5;4];

solution2 =A\B;
x = [0 0 0];
for ii = 1:100
    x(1) = (B(1) - A(1,2) * x(2) - A(1,3) * x(3))/A(1,1);
    x(2) = (B(2) - A(2,1) * x(1) - A(2,3) * x(3))/A(2,2);
    x(3) = (B(3) - A(3,1) * x(1) - A(3,2) * x(2))/A(3,3);
end

display(solution2);
display(x);


%set three

A = [-3 4 5; -2 2 -4; 0 2 -1];
B = [6; -3; 1];

solution3 =A\B;
x = [0 0 0];
for ii = 1:100
    x(1) = (B(1) - A(1,2) * x(2) - A(1,3) * x(3))/A(1,1);
    x(2) = (B(2) - A(2,1) * x(1) - A(2,3) * x(3))/A(2,2);
    x(3) = (B(3) - A(3,1) * x(1) - A(3,2) * x(2))/A(3,3);
end

display(solution3);
display(x);



Results

solution1 =

   1.0000e+00
   1.0000e+00
   1.0000e+00


x =

  -Inf  -Inf  -Inf


solution2 =

     1
     1
     1


x =

 -2.3612e+101  5.5271e+100 -4.1696e+101


solution3 =

   6.9565e-01
   9.3478e-01
   8.6957e-01


x =

  -1.6803e+93  -3.1205e+93  -6.2411e+93

All 3 sets diverge

No comments:

Post a Comment