SlideShare a Scribd company logo
1 of 18
EC 313: Numerical Methods                           Mayank Awasthi(2006033)
MATLAB Assignment – 2                               B.Tech 3rd Year(ECE)
                                                    Pdpm IIITDM, JABALPUR
Ques1:

Gauss Siedel Method for Solving the Linear Equations:
% Implementing Gauss Siedel method
% a is matrix whose diagonal elements are non-zero else rearrange it


function x = gauss_siedel(a,b,x)
 n=length(a);
 l=zeros(n,n);
 u=zeros(n,n);
 d=zeros(n,n);
 id=[1,0,0;0,1,0;0,0,1];
 for i=1:n
     for j=1:n
         a(i,j)= a(i,j)/a(i,i); %making the diagonal elements 1.

% Breaking the matrix as a sum of ( L+U+I )
         if i>j
             l(i,j)=a(i,j);
         end
         if i<j
             u(i,j)=a(i,j);
         end
         if i==j
             d(i,j)=a(i,j);
         end
     end
 end

%Implementing Norm of c where c = inverse(I+L)*U
 norm2(inv2(id+l)*u);
 if norm2(inv2(id+l)*u)>1
 fprintf('Norm of c is greater than 1, Solution will diverge');
 return;
 end
     for i=1:n
         b(i,1)=b(i,1)/a(i,i);
     end

% Calculating x using FORWARD DIFFERENCE CONCEPT
x=[0;0;0];
 for i=1:100
   x= forward_subs((l+d),(b-u*x));    m=a*x-b;
% Calculating(dis(A*x,b)<1e-6)to stop iteration at the given tolerance
   temp=0;
   for j=1:n
       temp=temp+power(m(j,1),2);
   end
   temp=sqrt(temp);
   if temp<0.0000001
      break;
       end
 end
  fprintf('nThe maximum no. of iteration required is %d',i);
end


MATLAB routine for Inverse of 3x3 matrix :
% Calculating Inverse of 3x3 matrix

function x = inv2(A)
I=[1,0,0;0,1,0;0,0,1];
n=length(A);
a21=A(2,1)/A(1,1);
for k = 1:n-1          % Elimination Phase
for i= k+1:n
if A(i,k) ~= 0
lambda = A(i,k)/A(k,k);
A(i,k:n) = A(i,k:n) - lambda*A(k,k:n);
I(i,k:n)= I(i,k:n) - lambda*I(k,k:n);
I(3,1)=I(2,1)*I(3,2)+I(3,1);
end
end
end
x1=back_subs(A,I(:,1)); % Backward Substitution
x2=back_subs(A,I(:,2));
x3=back_subs(A,I(:,3));
x=[x1,x2,x3];
end

MATLAB routine for Norm:
% Calculating Norm of matrix
function n0= norm2(c)
l=length(c);
n0=0;

    for m=1:l
        for n=1:l
            n0 = n0 + c(m,n)*c(m,n);
        end
    end
        n0=sqrt(n0);
  end
MATLAB routine for Forward Substitution:

% Implementing Forward Substitution

function x=forward_subs(A,b)
n=length(A);
for i = 1:3
   t=0;
    for j = 1:(i-1)
        t=t+A(i,j)*x(j);
    end
x(i,1)=(b(i,1)-t)/A(i,i);
end


Part1:                                       Part2:
>> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1]          >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1]
a=                                           a=

  1.0000     0.2000     0.2000                 1.0000     0.5000     0.5000
  0.2000     1.0000     0.2000                 0.5000     1.0000     0.5000
  0.2000     0.2000     1.0000                 0.5000     0.5000     1.0000

>> b=[2;2;2]                                 >> b=[2;2;2]

b=                                           b=

   2                                            2
   2                                            2
   2                                            2

>> x=[0;0;0]                                 >> x=[0;0;0]

x=                                           x=

   0                                            0
   0                                            0
   0                                            0

>> gauss_siedel(a,b,x)                       >> gauss_siedel(a,b,x)

The maximum no. of iteration required is 8   The maximum no of iteration required is 17
ans =                                        ans =

  1.4286                                       1.0000
  1.4286                                       1.0000
  1.4286                                       1.0000
Part3:

>> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1]
a=

  1.0000     0.9000     0.9000
  0.9000     1.0000     0.9000
  0.9000     0.9000     1.0000

>> b=[2;2;2]

b=

   2
   2
   2

>> x=[0;0;0]

x=

   0
   0
   0

>> gauss_siedel(a,b,x)

Norm of c is greater than 1, Solution will diverge
ans =

   0
   0
   0

************************************************************************

Spectral radius of C:

Spectral radius of C is maximum eigenvalue of C*CT.
In this case C=(I+L)-1 * U
1). >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1]
a=

  1.0000         0.2000       0.2000
  0.2000         1.0000       0.2000
  0.2000         0.2000       1.0000

>> L=[0,0,0;.2,0,0;.2,.2,0]
L=

     0           0        0
  0.2000            0         0
  0.2000         0.2000           0

>> I=[1,0,0;0,1,0;0,0,1]
I=

   1       0     0
   0       1     0
   0       0     1

>> U=[0,.2,.2;0,0,.2;0,0,0]
U=

       0       0.2000 0.2000
       0          0 0.2000
       0          0    0

>> C=inv2(I+L)*U
C=

       0 0.2000 0.2000
       0 -0.0400 0.1600
       0 -0.0320 -0.0720

>> lamda=eig(C*C')

lamda =

  0.0000
  0.0181
  0.0953

>> SR=max(lamda)
SR =                                      Spectral Radius
0.0953
2).
>> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1]
a=

  1.0000         0.5000       0.5000
  0.5000         1.0000       0.5000
  0.5000         0.5000       1.0000

>> L=[0,0,0;.5,0,0;.5,.5,0]
L=

     0           0        0
  0.5000            0         0
  0.5000         0.5000           0

>> I=[1,0,0;0,1,0;0,0,1]
I=

   1       0     0
   0       1     0
   0       0     1

>> U=[0,.5,.5;0,0,.5;0,0,0]
U=

       0       0.5000 0.5000
       0          0 0.5000
       0          0    0

>> C=inv2(I+L)*U
C=

       0 0.5000 0.5000
       0 -0.2500 0.2500
       0 -0.1250 -0.3750

>> lamda=eig(C*C')
lamda =

  0.0000
  0.1481
  0.6332

>> SR=max(lamda)
SR =                                   Spectral Radius
  0.6332
3).
>> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1]
a=

  1.0000         0.9000       0.9000
  0.9000         1.0000       0.9000
  0.9000         0.9000       1.0000

>> L=[0,0,0;.9,0,0;.9,.9,0]
L=

     0           0        0
  0.9000            0         0
  0.9000         0.9000           0

>> I=[1,0,0;0,1,0;0,0,1]
I=

   1       0     0
   0       1     0
   0       0     1

>> U=[0,.9,.9;0,0,.9;0,0,0]
U=

       0       0.9000 0.9000
       0          0 0.9000
       0          0    0

>> C=inv2(I+L)*U
C=

       0 0.9000 0.9000
       0 -0.8100 0.0900
       0 -0.0810 -0.8910

>> lamda=eig(C*C')
lamda =

  0.0000
  0.7301
  2.3546

>> SR=max(lamda)
SR =                                   Spectral Radius
2.3546
Steps vs t :




Spectral radius vs t :
Ques2:


Jacobi Method for Solving the Linear Equations:

%Implementing Jacobi Method
function x = jacobi(A,b,x)


I=[1 0 0; 0 1 0; 0 0 1];
c=I-A;

%Checking Norm
if norm2(c) > 1
     fprintf('nNorm is greater than one so it will diverge');
     return;
    end

    for j=1:50
x=b+(I-A)*x;
n=A*x-b;

%checking the condition of tolerance to stop the iterations
temp=0;
for i = 1:3
    temp= temp+ power(n(i,1),2);
end
   temp=sqrt(temp);
  if temp < 0.0001
      break;
  end
end
fprintf('nThe iteration required is %d',j);
end

MATLAB routine for Norm:
% Calculating Norm of matrix
function n0= norm2(c)
l=length(c);
n0=0;

    for m=1:l
        for n=1:l
            n0 = n0 + c(m,n)*c(m,n);
        end
    end
        n0=sqrt(n0);
  end
Part1:                                Part2

>> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1]   >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1]

a=                                    a=

  1.0000     0.2000     0.2000          1.0000     0.5000     0.5000
  0.2000     1.0000     0.2000          0.5000     1.0000     0.5000
  0.2000     0.2000     1.0000          0.5000     0.5000     1.0000

>> b=[2;2;2]                          >> b=[2;2;2]

b=                                    b=

   2                                     2
   2                                     2
   2                                     2

>> x=[0;0;0]                          >> x=[0;0;0]

x=                                    x=

   0                                     0
   0                                     0
   0                                     0

>> jacobi(a,b,x)                      >> jacobi(a,b,x)

The iteration required is 12          Norm is greater than one so it will diverge
ans =                                 ans =

  1.4285                                 0
  1.4285                                 0
  1.4285                                 0
Part3 :

>> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1]

a=

  1.0000     0.9000     0.9000
  0.9000     1.0000     0.9000
  0.9000     0.9000     1.0000

>> b=[2;2;2]

b=

   2
   2
   2

>> x=[0;0;0]

x=

   0
   0
   0

>> jacobi(a,b,x)

Norm is greater than one so it will diverge
ans =

   0
   0
   0

From the Data we have calculated we find that Gauss_Siedel Method Diverge more
fastly than Jacobi Method.
Ques3:



Cholesky Method for Solving the Linear Equations:
% Implementing Cholesky Method
function x = cholesky(A,b,x)
n=length(A)
l(1,1)=sqrt(A(1,1));
for i=2:n
    l(i,1)=A(i,1)/l(1,1);
end

for j=2:(n-1)
    temp=0;
    for k=1:j-1
    temp=temp+l(j,k)*l(j,k);
    end
    l(j,j)= sqrt(A(j,j)-temp);
end

for j=2:(n-1)
    for i=j+1:n
        temp=0;
        for k=1:j-1
        temp=temp+l(i,k)*l(j,k);
        end
l(i,j)=(A(i,j)-temp)/l(j,j);
    end

end
temp1=l(n,1)*l(n,1)+l(n,2)*l(n,2);
l(n,n)=sqrt(A(n,n)-temp1);

y=forward_subs(l,b);    %Using Forward Substitution Concept
x=back_subs(l',y);
end
Part1:                                Part2

>> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1]   >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1]
a=                                    a=

  1.0000     0.2000     0.2000          1.0000     0.5000     0.5000
  0.2000     1.0000     0.2000          0.5000     1.0000     0.5000
  0.2000     0.2000     1.0000          0.5000     0.5000     1.0000

>> b=[2;2;2]                          >> b=[2;2;2]

b=                                    b=

   2                                     2
   2                                     2
   2                                     2

>> x=[0;0;0]                          >> x=[0;0;0]
x=                                    x=

   0                                     0
   0                                     0
   0                                     0

>> cholesky(a,b,x)                    >> cholesky(a,b,x)
ans =                                 ans =

  1.4286                                1.0000
  1.4286                                1.0000
  1.4286                                1.0000
Part3:
>> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1]
a=

  1.0000     0.9000     0.9000
  0.9000     1.0000     0.9000
  0.9000     0.9000     1.0000

>> b=[2;2;2]
b=

   2
   2
   2

>> x=[0;0;0]
x=

   0
   0
   0

>> cholesky(a,b,x)

ans =

  0.7143
  0.7143
  0.7143
Ques4:

Matlab Subroutine to calculate Condition Number:
% Calculating Condition Number

function [] = cond(a,b,b1);
x0=[0;0;0];
val1=max(abs(eig(a)));
val2=min(abs(eig(a)));

val=val1/val2                  %definition of Condition number

x=gauss_siedel(a,b,x0);
x1=gauss_siedel(a,b1,x0);
errip=norm(x-x1)/norm(x);
errop=norm(b-b1)/norm(b);
fprintf('nerror in i/p is %d          nand error in o/p is
%dn',errip,errop);

end




1).
>> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1]

a=

  1.0000     0.2000     0.2000
  0.2000     1.0000     0.2000
  0.2000     0.2000     1.0000

>> b=[2;2;2]

b=

   2
   2
   2

>> b1=[1.1;2.1;3.1]

b1 =

  1.1000
  2.1000
  3.1000
>> cond(a,b,b1)

a=

  1.0800     0.4400     0.4400
  0.4400     1.0800     0.4400
  0.4400     0.4400     1.0800


val =

  3.0625              Condition Number.


The maximum no. of iteration required is 14
error in i/p is 1.309812e+000
and error in o/p is 4.112988e-001



2).
>> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1]

a=

  1.0000     0.5000     0.5000
  0.5000     1.0000     0.5000
  0.5000     0.5000     1.0000

>> b=[2;2;2]

b=

   2
   2
   2

>> b1=[1.1;2.1;3.1]

b1 =

  1.1000
  2.1000
  3.1000
>> cond(a,b,b1)
a=

  1.5000     1.2500     1.2500
  1.2500     1.5000     1.2500
  1.2500     1.2500     1.5000

val =

 16.0000          Condition Number
Norm of c is greater than 1, Solution will diverge.


3).
>> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1]

a=

  1.0000     0.9000     0.9000
  0.9000     1.0000     0.9000
  0.9000     0.9000     1.0000

>> b1=[1.1;2.1;3.1]
b1 =

  1.1000
  2.1000
  3.1000

>> b1=[1.1;2.1;3.1]

b1 =

  1.1000
  2.1000
  3.1000

>> b=[2;2;2]
b=

   2
   2
   2
>> cond(a,b,b1)

a=

  2.6200   2.6100   2.6100
  2.6100   2.6200   2.6100
  2.6100   2.6100   2.6200


val =

 28.0000                  Condition Number.

Norm of c is greater than 1, Solution will diverge.

More Related Content

What's hot

Common derivatives integrals
Common derivatives integralsCommon derivatives integrals
Common derivatives integralsolziich
 
Applied numerical methods lec12
Applied numerical methods lec12Applied numerical methods lec12
Applied numerical methods lec12Yasser Ahmed
 
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesIIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesSOURAV DAS
 
2012 mdsp pr10 ica
2012 mdsp pr10 ica2012 mdsp pr10 ica
2012 mdsp pr10 icanozomuhamada
 
Lecture 11 systems of nonlinear equations
Lecture 11 systems of nonlinear equationsLecture 11 systems of nonlinear equations
Lecture 11 systems of nonlinear equationsHazel Joy Chong
 
Point Collocation Method used in the solving of Differential Equations, parti...
Point Collocation Method used in the solving of Differential Equations, parti...Point Collocation Method used in the solving of Differential Equations, parti...
Point Collocation Method used in the solving of Differential Equations, parti...Suddhasheel GHOSH, PhD
 
Engr 213 midterm 2b sol 2010
Engr 213 midterm 2b sol 2010Engr 213 midterm 2b sol 2010
Engr 213 midterm 2b sol 2010akabaka12
 
2012 mdsp pr09 pca lda
2012 mdsp pr09 pca lda2012 mdsp pr09 pca lda
2012 mdsp pr09 pca ldanozomuhamada
 
Engr 213 midterm 2b 2009
Engr 213 midterm 2b 2009Engr 213 midterm 2b 2009
Engr 213 midterm 2b 2009akabaka12
 
FEM Introduction: Solving ODE-BVP using the Galerkin's Method
FEM Introduction: Solving ODE-BVP using the Galerkin's MethodFEM Introduction: Solving ODE-BVP using the Galerkin's Method
FEM Introduction: Solving ODE-BVP using the Galerkin's MethodSuddhasheel GHOSH, PhD
 
2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machinenozomuhamada
 
Engr 213 midterm 2a sol 2009
Engr 213 midterm 2a sol 2009Engr 213 midterm 2a sol 2009
Engr 213 midterm 2a sol 2009akabaka12
 
Solve ODE - BVP through the Least Squares Method
Solve ODE - BVP through the Least Squares MethodSolve ODE - BVP through the Least Squares Method
Solve ODE - BVP through the Least Squares MethodSuddhasheel GHOSH, PhD
 
2012 mdsp pr11 ica part 2 face recognition
2012 mdsp pr11 ica part 2 face recognition2012 mdsp pr11 ica part 2 face recognition
2012 mdsp pr11 ica part 2 face recognitionnozomuhamada
 
C3 Transformations
C3 TransformationsC3 Transformations
C3 TransformationsJJkedst
 

What's hot (19)

Common derivatives integrals
Common derivatives integralsCommon derivatives integrals
Common derivatives integrals
 
Applied numerical methods lec12
Applied numerical methods lec12Applied numerical methods lec12
Applied numerical methods lec12
 
Ch02
Ch02Ch02
Ch02
 
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesIIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
 
2012 mdsp pr10 ica
2012 mdsp pr10 ica2012 mdsp pr10 ica
2012 mdsp pr10 ica
 
Lecture 11 systems of nonlinear equations
Lecture 11 systems of nonlinear equationsLecture 11 systems of nonlinear equations
Lecture 11 systems of nonlinear equations
 
Point Collocation Method used in the solving of Differential Equations, parti...
Point Collocation Method used in the solving of Differential Equations, parti...Point Collocation Method used in the solving of Differential Equations, parti...
Point Collocation Method used in the solving of Differential Equations, parti...
 
Engr 213 midterm 2b sol 2010
Engr 213 midterm 2b sol 2010Engr 213 midterm 2b sol 2010
Engr 213 midterm 2b sol 2010
 
2012 mdsp pr09 pca lda
2012 mdsp pr09 pca lda2012 mdsp pr09 pca lda
2012 mdsp pr09 pca lda
 
Assignment6
Assignment6Assignment6
Assignment6
 
Engr 213 midterm 2b 2009
Engr 213 midterm 2b 2009Engr 213 midterm 2b 2009
Engr 213 midterm 2b 2009
 
FEM Introduction: Solving ODE-BVP using the Galerkin's Method
FEM Introduction: Solving ODE-BVP using the Galerkin's MethodFEM Introduction: Solving ODE-BVP using the Galerkin's Method
FEM Introduction: Solving ODE-BVP using the Galerkin's Method
 
2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine
 
Engr 213 midterm 2a sol 2009
Engr 213 midterm 2a sol 2009Engr 213 midterm 2a sol 2009
Engr 213 midterm 2a sol 2009
 
Solve ODE - BVP through the Least Squares Method
Solve ODE - BVP through the Least Squares MethodSolve ODE - BVP through the Least Squares Method
Solve ODE - BVP through the Least Squares Method
 
exponen dan logaritma
exponen dan logaritmaexponen dan logaritma
exponen dan logaritma
 
2012 mdsp pr11 ica part 2 face recognition
2012 mdsp pr11 ica part 2 face recognition2012 mdsp pr11 ica part 2 face recognition
2012 mdsp pr11 ica part 2 face recognition
 
Sol75
Sol75Sol75
Sol75
 
C3 Transformations
C3 TransformationsC3 Transformations
C3 Transformations
 

Viewers also liked

La fuente de vida destruida por la violencia
La fuente de vida destruida por la violenciaLa fuente de vida destruida por la violencia
La fuente de vida destruida por la violenciaZarey Rojas
 
Educational policiec 8913 syeda mehvish dildar
Educational policiec 8913 syeda mehvish dildarEducational policiec 8913 syeda mehvish dildar
Educational policiec 8913 syeda mehvish dildarMehvishwish
 
מדדים מרכזיים על מצבם של יוצאי אתיופיה
מדדים מרכזיים על מצבם של יוצאי אתיופיהמדדים מרכזיים על מצבם של יוצאי אתיופיה
מדדים מרכזיים על מצבם של יוצאי אתיופיהmjbinstitute
 
Ppt 1 t16 pt 3 (1)
Ppt 1 t16 pt 3 (1)Ppt 1 t16 pt 3 (1)
Ppt 1 t16 pt 3 (1)Magnesita_ri
 
MANAGEMENT OF HYPEREMESIS GRAVIDARUM
    MANAGEMENT OF HYPEREMESIS GRAVIDARUM    MANAGEMENT OF HYPEREMESIS GRAVIDARUM
MANAGEMENT OF HYPEREMESIS GRAVIDARUMmamuni00g2
 

Viewers also liked (9)

La fuente de vida destruida por la violencia
La fuente de vida destruida por la violenciaLa fuente de vida destruida por la violencia
La fuente de vida destruida por la violencia
 
My ed tech
My ed techMy ed tech
My ed tech
 
HHMI AERIAL_NIGHT
HHMI AERIAL_NIGHTHHMI AERIAL_NIGHT
HHMI AERIAL_NIGHT
 
Normas APA
Normas APANormas APA
Normas APA
 
Educational policiec 8913 syeda mehvish dildar
Educational policiec 8913 syeda mehvish dildarEducational policiec 8913 syeda mehvish dildar
Educational policiec 8913 syeda mehvish dildar
 
מדדים מרכזיים על מצבם של יוצאי אתיופיה
מדדים מרכזיים על מצבם של יוצאי אתיופיהמדדים מרכזיים על מצבם של יוצאי אתיופיה
מדדים מרכזיים על מצבם של יוצאי אתיופיה
 
Ppt 1 t16 pt 3 (1)
Ppt 1 t16 pt 3 (1)Ppt 1 t16 pt 3 (1)
Ppt 1 t16 pt 3 (1)
 
MANAGEMENT OF HYPEREMESIS GRAVIDARUM
    MANAGEMENT OF HYPEREMESIS GRAVIDARUM    MANAGEMENT OF HYPEREMESIS GRAVIDARUM
MANAGEMENT OF HYPEREMESIS GRAVIDARUM
 
Lithuania
LithuaniaLithuania
Lithuania
 

Similar to jacobi method, gauss siedel for solving linear equations

Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3AhsanIrshad8
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)asghar123456
 
Solution of matlab chapter 1
Solution of matlab chapter 1Solution of matlab chapter 1
Solution of matlab chapter 1AhsanIrshad8
 
LP Graphical Solution
LP Graphical SolutionLP Graphical Solution
LP Graphical Solutionunemployedmba
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)asghar123456
 
Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Sudersana Viswanathan
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)asghar123456
 
130 problemas dispositivos electronicos lopez meza brayan
130 problemas dispositivos electronicos lopez meza brayan130 problemas dispositivos electronicos lopez meza brayan
130 problemas dispositivos electronicos lopez meza brayanbrandwin marcelo lavado
 
Calculus Early Transcendentals 10th Edition Anton Solutions Manual
Calculus Early Transcendentals 10th Edition Anton Solutions ManualCalculus Early Transcendentals 10th Edition Anton Solutions Manual
Calculus Early Transcendentals 10th Edition Anton Solutions Manualnodyligomi
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.Alexander Decker
 
lecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxlecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxAYMENGOODKid
 
Solutions Manual for Calculus Early Transcendentals 10th Edition by Anton
Solutions Manual for Calculus Early Transcendentals 10th Edition by AntonSolutions Manual for Calculus Early Transcendentals 10th Edition by Anton
Solutions Manual for Calculus Early Transcendentals 10th Edition by AntonPamelaew
 
Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...journal ijrtem
 
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기NAVER D2
 
Matlab lab manual
Matlab lab manualMatlab lab manual
Matlab lab manualnmahi96
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfWaleedHussain30
 

Similar to jacobi method, gauss siedel for solving linear equations (20)

Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 
Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)
 
Solution of matlab chapter 1
Solution of matlab chapter 1Solution of matlab chapter 1
Solution of matlab chapter 1
 
LP Graphical Solution
LP Graphical SolutionLP Graphical Solution
LP Graphical Solution
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)
 
Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Trigonometric ratios and identities 1
Trigonometric ratios and identities 1
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 
DC servo motor
DC servo motorDC servo motor
DC servo motor
 
130 problemas dispositivos electronicos lopez meza brayan
130 problemas dispositivos electronicos lopez meza brayan130 problemas dispositivos electronicos lopez meza brayan
130 problemas dispositivos electronicos lopez meza brayan
 
Calculus Early Transcendentals 10th Edition Anton Solutions Manual
Calculus Early Transcendentals 10th Edition Anton Solutions ManualCalculus Early Transcendentals 10th Edition Anton Solutions Manual
Calculus Early Transcendentals 10th Edition Anton Solutions Manual
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.
 
lecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxlecture 5 courseII (6).pptx
lecture 5 courseII (6).pptx
 
Solutions Manual for Calculus Early Transcendentals 10th Edition by Anton
Solutions Manual for Calculus Early Transcendentals 10th Edition by AntonSolutions Manual for Calculus Early Transcendentals 10th Edition by Anton
Solutions Manual for Calculus Early Transcendentals 10th Edition by Anton
 
Chapter four
Chapter fourChapter four
Chapter four
 
Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...
 
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기
[112] 모바일 환경에서 실시간 Portrait Segmentation 구현하기
 
Matlab lab manual
Matlab lab manualMatlab lab manual
Matlab lab manual
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdf
 

More from Department of Telecommunications, Ministry of Communication & IT (INDIA) (7)

Workshop proposal
Workshop proposalWorkshop proposal
Workshop proposal
 
Feeding system for disabled report
Feeding system for disabled reportFeeding system for disabled report
Feeding system for disabled report
 
Design ideas mayank
Design ideas mayankDesign ideas mayank
Design ideas mayank
 
Adaptive signal processing simon haykins
Adaptive signal processing simon haykinsAdaptive signal processing simon haykins
Adaptive signal processing simon haykins
 
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil codePdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
 
Analogic
AnalogicAnalogic
Analogic
 
An Introduction To Speech Recognition
An Introduction To Speech RecognitionAn Introduction To Speech Recognition
An Introduction To Speech Recognition
 

Recently uploaded

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 

Recently uploaded (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

jacobi method, gauss siedel for solving linear equations

  • 1. EC 313: Numerical Methods Mayank Awasthi(2006033) MATLAB Assignment – 2 B.Tech 3rd Year(ECE) Pdpm IIITDM, JABALPUR Ques1: Gauss Siedel Method for Solving the Linear Equations: % Implementing Gauss Siedel method % a is matrix whose diagonal elements are non-zero else rearrange it function x = gauss_siedel(a,b,x) n=length(a); l=zeros(n,n); u=zeros(n,n); d=zeros(n,n); id=[1,0,0;0,1,0;0,0,1]; for i=1:n for j=1:n a(i,j)= a(i,j)/a(i,i); %making the diagonal elements 1. % Breaking the matrix as a sum of ( L+U+I ) if i>j l(i,j)=a(i,j); end if i<j u(i,j)=a(i,j); end if i==j d(i,j)=a(i,j); end end end %Implementing Norm of c where c = inverse(I+L)*U norm2(inv2(id+l)*u); if norm2(inv2(id+l)*u)>1 fprintf('Norm of c is greater than 1, Solution will diverge'); return; end for i=1:n b(i,1)=b(i,1)/a(i,i); end % Calculating x using FORWARD DIFFERENCE CONCEPT x=[0;0;0]; for i=1:100 x= forward_subs((l+d),(b-u*x)); m=a*x-b;
  • 2. % Calculating(dis(A*x,b)<1e-6)to stop iteration at the given tolerance temp=0; for j=1:n temp=temp+power(m(j,1),2); end temp=sqrt(temp); if temp<0.0000001 break; end end fprintf('nThe maximum no. of iteration required is %d',i); end MATLAB routine for Inverse of 3x3 matrix : % Calculating Inverse of 3x3 matrix function x = inv2(A) I=[1,0,0;0,1,0;0,0,1]; n=length(A); a21=A(2,1)/A(1,1); for k = 1:n-1 % Elimination Phase for i= k+1:n if A(i,k) ~= 0 lambda = A(i,k)/A(k,k); A(i,k:n) = A(i,k:n) - lambda*A(k,k:n); I(i,k:n)= I(i,k:n) - lambda*I(k,k:n); I(3,1)=I(2,1)*I(3,2)+I(3,1); end end end x1=back_subs(A,I(:,1)); % Backward Substitution x2=back_subs(A,I(:,2)); x3=back_subs(A,I(:,3)); x=[x1,x2,x3]; end MATLAB routine for Norm: % Calculating Norm of matrix function n0= norm2(c) l=length(c); n0=0; for m=1:l for n=1:l n0 = n0 + c(m,n)*c(m,n); end end n0=sqrt(n0); end
  • 3. MATLAB routine for Forward Substitution: % Implementing Forward Substitution function x=forward_subs(A,b) n=length(A); for i = 1:3 t=0; for j = 1:(i-1) t=t+A(i,j)*x(j); end x(i,1)=(b(i,1)-t)/A(i,i); end Part1: Part2: >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1] >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1] a= a= 1.0000 0.2000 0.2000 1.0000 0.5000 0.5000 0.2000 1.0000 0.2000 0.5000 1.0000 0.5000 0.2000 0.2000 1.0000 0.5000 0.5000 1.0000 >> b=[2;2;2] >> b=[2;2;2] b= b= 2 2 2 2 2 2 >> x=[0;0;0] >> x=[0;0;0] x= x= 0 0 0 0 0 0 >> gauss_siedel(a,b,x) >> gauss_siedel(a,b,x) The maximum no. of iteration required is 8 The maximum no of iteration required is 17 ans = ans = 1.4286 1.0000 1.4286 1.0000 1.4286 1.0000
  • 4. Part3: >> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1] a= 1.0000 0.9000 0.9000 0.9000 1.0000 0.9000 0.9000 0.9000 1.0000 >> b=[2;2;2] b= 2 2 2 >> x=[0;0;0] x= 0 0 0 >> gauss_siedel(a,b,x) Norm of c is greater than 1, Solution will diverge ans = 0 0 0 ************************************************************************ Spectral radius of C: Spectral radius of C is maximum eigenvalue of C*CT. In this case C=(I+L)-1 * U
  • 5. 1). >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1] a= 1.0000 0.2000 0.2000 0.2000 1.0000 0.2000 0.2000 0.2000 1.0000 >> L=[0,0,0;.2,0,0;.2,.2,0] L= 0 0 0 0.2000 0 0 0.2000 0.2000 0 >> I=[1,0,0;0,1,0;0,0,1] I= 1 0 0 0 1 0 0 0 1 >> U=[0,.2,.2;0,0,.2;0,0,0] U= 0 0.2000 0.2000 0 0 0.2000 0 0 0 >> C=inv2(I+L)*U C= 0 0.2000 0.2000 0 -0.0400 0.1600 0 -0.0320 -0.0720 >> lamda=eig(C*C') lamda = 0.0000 0.0181 0.0953 >> SR=max(lamda) SR = Spectral Radius 0.0953
  • 6. 2). >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1] a= 1.0000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 1.0000 >> L=[0,0,0;.5,0,0;.5,.5,0] L= 0 0 0 0.5000 0 0 0.5000 0.5000 0 >> I=[1,0,0;0,1,0;0,0,1] I= 1 0 0 0 1 0 0 0 1 >> U=[0,.5,.5;0,0,.5;0,0,0] U= 0 0.5000 0.5000 0 0 0.5000 0 0 0 >> C=inv2(I+L)*U C= 0 0.5000 0.5000 0 -0.2500 0.2500 0 -0.1250 -0.3750 >> lamda=eig(C*C') lamda = 0.0000 0.1481 0.6332 >> SR=max(lamda) SR = Spectral Radius 0.6332
  • 7. 3). >> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1] a= 1.0000 0.9000 0.9000 0.9000 1.0000 0.9000 0.9000 0.9000 1.0000 >> L=[0,0,0;.9,0,0;.9,.9,0] L= 0 0 0 0.9000 0 0 0.9000 0.9000 0 >> I=[1,0,0;0,1,0;0,0,1] I= 1 0 0 0 1 0 0 0 1 >> U=[0,.9,.9;0,0,.9;0,0,0] U= 0 0.9000 0.9000 0 0 0.9000 0 0 0 >> C=inv2(I+L)*U C= 0 0.9000 0.9000 0 -0.8100 0.0900 0 -0.0810 -0.8910 >> lamda=eig(C*C') lamda = 0.0000 0.7301 2.3546 >> SR=max(lamda) SR = Spectral Radius 2.3546
  • 8. Steps vs t : Spectral radius vs t :
  • 9. Ques2: Jacobi Method for Solving the Linear Equations: %Implementing Jacobi Method function x = jacobi(A,b,x) I=[1 0 0; 0 1 0; 0 0 1]; c=I-A; %Checking Norm if norm2(c) > 1 fprintf('nNorm is greater than one so it will diverge'); return; end for j=1:50 x=b+(I-A)*x; n=A*x-b; %checking the condition of tolerance to stop the iterations temp=0; for i = 1:3 temp= temp+ power(n(i,1),2); end temp=sqrt(temp); if temp < 0.0001 break; end end fprintf('nThe iteration required is %d',j); end MATLAB routine for Norm: % Calculating Norm of matrix function n0= norm2(c) l=length(c); n0=0; for m=1:l for n=1:l n0 = n0 + c(m,n)*c(m,n); end end n0=sqrt(n0); end
  • 10. Part1: Part2 >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1] >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1] a= a= 1.0000 0.2000 0.2000 1.0000 0.5000 0.5000 0.2000 1.0000 0.2000 0.5000 1.0000 0.5000 0.2000 0.2000 1.0000 0.5000 0.5000 1.0000 >> b=[2;2;2] >> b=[2;2;2] b= b= 2 2 2 2 2 2 >> x=[0;0;0] >> x=[0;0;0] x= x= 0 0 0 0 0 0 >> jacobi(a,b,x) >> jacobi(a,b,x) The iteration required is 12 Norm is greater than one so it will diverge ans = ans = 1.4285 0 1.4285 0 1.4285 0
  • 11. Part3 : >> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1] a= 1.0000 0.9000 0.9000 0.9000 1.0000 0.9000 0.9000 0.9000 1.0000 >> b=[2;2;2] b= 2 2 2 >> x=[0;0;0] x= 0 0 0 >> jacobi(a,b,x) Norm is greater than one so it will diverge ans = 0 0 0 From the Data we have calculated we find that Gauss_Siedel Method Diverge more fastly than Jacobi Method.
  • 12. Ques3: Cholesky Method for Solving the Linear Equations: % Implementing Cholesky Method function x = cholesky(A,b,x) n=length(A) l(1,1)=sqrt(A(1,1)); for i=2:n l(i,1)=A(i,1)/l(1,1); end for j=2:(n-1) temp=0; for k=1:j-1 temp=temp+l(j,k)*l(j,k); end l(j,j)= sqrt(A(j,j)-temp); end for j=2:(n-1) for i=j+1:n temp=0; for k=1:j-1 temp=temp+l(i,k)*l(j,k); end l(i,j)=(A(i,j)-temp)/l(j,j); end end temp1=l(n,1)*l(n,1)+l(n,2)*l(n,2); l(n,n)=sqrt(A(n,n)-temp1); y=forward_subs(l,b); %Using Forward Substitution Concept x=back_subs(l',y); end
  • 13. Part1: Part2 >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1] >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1] a= a= 1.0000 0.2000 0.2000 1.0000 0.5000 0.5000 0.2000 1.0000 0.2000 0.5000 1.0000 0.5000 0.2000 0.2000 1.0000 0.5000 0.5000 1.0000 >> b=[2;2;2] >> b=[2;2;2] b= b= 2 2 2 2 2 2 >> x=[0;0;0] >> x=[0;0;0] x= x= 0 0 0 0 0 0 >> cholesky(a,b,x) >> cholesky(a,b,x) ans = ans = 1.4286 1.0000 1.4286 1.0000 1.4286 1.0000
  • 14. Part3: >> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1] a= 1.0000 0.9000 0.9000 0.9000 1.0000 0.9000 0.9000 0.9000 1.0000 >> b=[2;2;2] b= 2 2 2 >> x=[0;0;0] x= 0 0 0 >> cholesky(a,b,x) ans = 0.7143 0.7143 0.7143
  • 15. Ques4: Matlab Subroutine to calculate Condition Number: % Calculating Condition Number function [] = cond(a,b,b1); x0=[0;0;0]; val1=max(abs(eig(a))); val2=min(abs(eig(a))); val=val1/val2 %definition of Condition number x=gauss_siedel(a,b,x0); x1=gauss_siedel(a,b1,x0); errip=norm(x-x1)/norm(x); errop=norm(b-b1)/norm(b); fprintf('nerror in i/p is %d nand error in o/p is %dn',errip,errop); end 1). >> a=[1 ,.2 .2;.2, 1, .2;.2, .2, 1] a= 1.0000 0.2000 0.2000 0.2000 1.0000 0.2000 0.2000 0.2000 1.0000 >> b=[2;2;2] b= 2 2 2 >> b1=[1.1;2.1;3.1] b1 = 1.1000 2.1000 3.1000
  • 16. >> cond(a,b,b1) a= 1.0800 0.4400 0.4400 0.4400 1.0800 0.4400 0.4400 0.4400 1.0800 val = 3.0625 Condition Number. The maximum no. of iteration required is 14 error in i/p is 1.309812e+000 and error in o/p is 4.112988e-001 2). >> a=[1 ,.5 .5;.5, 1, .5;.5, .5, 1] a= 1.0000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 1.0000 >> b=[2;2;2] b= 2 2 2 >> b1=[1.1;2.1;3.1] b1 = 1.1000 2.1000 3.1000
  • 17. >> cond(a,b,b1) a= 1.5000 1.2500 1.2500 1.2500 1.5000 1.2500 1.2500 1.2500 1.5000 val = 16.0000 Condition Number Norm of c is greater than 1, Solution will diverge. 3). >> a=[1 ,.9 .9;.9, 1, .9;.9, .9, 1] a= 1.0000 0.9000 0.9000 0.9000 1.0000 0.9000 0.9000 0.9000 1.0000 >> b1=[1.1;2.1;3.1] b1 = 1.1000 2.1000 3.1000 >> b1=[1.1;2.1;3.1] b1 = 1.1000 2.1000 3.1000 >> b=[2;2;2] b= 2 2 2
  • 18. >> cond(a,b,b1) a= 2.6200 2.6100 2.6100 2.6100 2.6200 2.6100 2.6100 2.6100 2.6200 val = 28.0000 Condition Number. Norm of c is greater than 1, Solution will diverge.