Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Jacobi method to solve equation using MATLAB(mfile)


% Jacobi method

 n=input('Enter number of equations, n:  ');
 A = zeros(n,n+1);
 x1 = zeros(n);
 x2 = zeros(n);
 tol = input('Enter the tolerance, tol: ');
 m = input('Enter maximum number of iterations, m:  ');

 A=[4 2 3 8; 3 -5 2 -14; -2 3 8 27];
 x1=[0 0 0];

 k = 1;
 while k <= m
   err = 0;
   for i = 1 : n
      s = 0;
      for j = 1 : n
        s = s-A(i,j)*x1(j);
      end
      s = (s+A(i,n+1))/A(i,i);
      if abs(s) > err
        err = abs(s);
      end
      x2(i) = x1(i)+s;
  end

  if err <= tol
     break;
  else
     k = k+1;
     for i = 1 : n
       x1(i) = x2(i);
     end
  end
 end

 fprintf('Solution vector after %d iterations is :\n', k-1);
 for i = 1 : n
    fprintf(' %11.8f \n', x2(i));

 end


Output:

>> jacobimethod
Enter number of equations, n:  3
Enter the tolerance, tol: 0.001
Enter maximum number of iterations, m:  100
Solution vector after 41 iterations is :
 -0.99919498 
  2.99974076 
  2.00028882 
>> 



3 comments:

  1. Indulge in the rich, velvety pleasure of a chocolate bar in Riyadh, where each delightful bite is a sweet escape into heavenly cocoa bliss. Savor the exquisite flavors amidst the vibrant energy of the capital city.

    ReplyDelete
  2. The Jacobi method implemented in MATLAB provides an effective way to solve linear equations iteratively. It's a powerful numerical technique for finding approximate solutions, particularly handy for large systems. The clarity of the MATLAB m-file makes it easy to understand and customize for different equations. Incorporatingهوت شوكليت into the coding sessions adds a delightful twist, making the journey of solving equations even sweeter. Happy coding and indulging in a bit of chocolate goodness!

    ReplyDelete
  3. Embark on a seamless academic journey with Assignment Help USA. Our expert writers curate personalized solutions, ensuring top-notch assignments that align with the rigor of American education. From essays to dissertations, we deliver excellence on time.

    ReplyDelete

Popular Posts