Jacobi Gauss
Jacobi Gauss
A =
5 -2 3 0
-3 9 1 -2
2 -1 -7 1
4 3 -5 7
b =
-1.00000
2.00000
3.00000
0.50000
x =
0
octave:4> n=size(x,1);
octave:5> normVal=Inf;
iterations',x,itr);
0.178697
0.230293
-0.477635
-0.470549 in 8 iterations
octave:1> %% Gauss Seidel Method
octave:1> %% Solution of x in Ax=b using Gauss Seidel Method
octave:1> % * _*Initailize 'A' 'b' & intial guess 'x'*_
octave:1> A=[9 -9 9 9;-9 9 9 -9;9 -9 -9 9; 9 9 -9 9]
A =
9 -9 9 9
-9 9 9 -9
9 -9 -9 9
9 9 -9 9
-1.00000
2.00000
3.00000
0.50000
0
0
0
0
octave:4> n=size(x,1);
octave:5> normVal=Inf;
octave:6> % * _*Tolerence for method*_
octave:6> tol=1e-5; itr=0;
octave:7> %% Algorithm: Gauss Seidel Method
octave:7> while normVal>tol
> > x_old=x;
> > for i=1:n
> > sigma=0;
> > for j=1:i-1
> > sigma=sigma+A(i,j)*x(j);
> > end
> > for j=i+1:n
> > sigma=sigma+A(i,j)*x_old(j);
> > end
> > x(i)=(1/A(i,i))*(b(i)-sigma);
> > end
> > itr=itr+1;
> > normVal=norm(x_old-x);
> > end
octave:7> fprintf('Solution of the system is : \n%f\n%f\n%f\n%f in
%d iterations',x,itr);
Solution of the system is :
398218333693.026062
58306571.611762
-5691.666667
-398276645956.248901 in 10245 iterations
Jacobi Method
octave:1> %% Jacobi Method
octave:1> %% Solution of x in Ax=b using Jacobi Method
octave:1> % * _*Initailize 'A' 'b' & intial guess 'x'*_
octave:1> A=[5 -2 3 0;-3 9 1 -2;2 -1 -7 1; 4 3 -5 7]
A =
5 -2 3 0
-3 9 1 -2
2 -1 -7 1
4 3 -5 7
-1.00000
2.00000
3.00000
0.50000
0
0
0
0
octave:4> n=size(x,1);
octave:5> normVal=Inf;
octave:6> % * _*Tolerence for method*_
octave:6> tol=1e-5; itr=0;
octave:7> %% Algorithm: Jacobi Method
octave:7> while normVal>tol
> > xold=x;
> > for i=1:n
> > sigma=0;
> > for j=1:n
> > if j~=i
> > sigma=sigma+A(i,j)*x(j);
> > end
> > end
> > x(i)=(1/A(i,i))*(b(i)-sigma);
> > end
> > itr=itr+1;
> > normVal=abs(xold-x);
> > end
octave:8> fprintf('Solution of the system is : \n%f\n%f\n%f\n%f in %d
iterations',x,itr);
Solution of the system is :
0.178697
0.230293
-0.477635
-0.470549 in 8 iterations
octave:1> %% Jacobi Method
octave:1> %% Solution of x in Ax=b using Jacobi Method
octave:1> % * _*Initailize 'A' 'b' & intial guess 'x'*_
octave:1> A=[5 -1 2 1;-2 1 2 -1;2 -1 -2 1; 2 1 -2 1]
A =
5 -1 2 1
-2 1 2 -1
2 -1 -2 1
2 1 -2 1
-1.00000
2.00000
3.00000
0.50000
0
0
0
0
octave:4> n=size(x,1);
octave:5> normVal=Inf;
octave:6> % * _*Tolerence for method*_
octave:6> tol=1e-5; itr=0;
octave:7> %% Algorithm: Jacobi Method
octave:7> while normVal>tol
> > xold=x;
> > for i=1:n
> > sigma=0;
> > for j=1:n
> > if j~=i
> > sigma=sigma+A(i,j)*x(j);
> > end
> > end
> > x(i)=(1/A(i,i))*(b(i)-sigma);
> > end
> > itr=itr+1;
> > normVal=abs(xold-x);
> > end
octave:8> fprintf('Solution of the system is : \n%f\n%f\n%f\n%f in %d
iterations',x,itr);
Solution of the system is :
97.000001
4.583338
-75.000000
-348.083341 in 30 iterations