Question

In: Advanced Math

**Using Matlab** Make the program for Jacobi iteration method and compare solutions obtaned by two algorithms,...

**Using Matlab**

  • Make the program for Jacobi iteration method and compare solutions obtaned by two algorithms, Jacobi-iteration method and Gaussian elimination.

Solutions

Expert Solution

%%% Gauss Ellimination

function [ Ahat, x]=GaussElim( A,b)
if det(A)==0
disp('Unique solution is not possible : \n');
else
[r c]=size(A);
for n=1:r
Ahat(n,:)=[A(n,:) b(n)];
end
for i=1:r
k=0;
for j=1:c
  
if (i==j)
Ahat(i,:)=Ahat(i,:)/Ahat(i,j);
k=1;
end
if ( j > i)
if (k==1)
Ahat(j,:)=Ahat(j,:)-Ahat(j,i)*Ahat(i,:);
end
end
  
end
end
x(1:r)=0;
x(r)=Ahat(end,end);
for i=r-1:-1:1
for j=c:-1:1
if (j > i)
x(i)=x(i)-x(j)*Ahat(i,j);
end
end
x(i)=x(i)+Ahat(i,end);
end

end
end

%%% Jacobi iteration

function [ x1]= jacobi ( A, b);
tol=10^(-5);
disp('Gauss jacobi method');
[r,c]=size(A);
for n=1:r
for k=1:c
if (n==k)
D(n,k)=A(n,k);
else
R(n,k)=A(n,k);
end
end
end

x(:,1)=[0 0 0]'; %%%Initial guess
disp('Solution at each iteration ');
% fprintf(' d p g \n');
for n=1:40
x(:,n+1)=inv(D)*(b-R*x(:,n));
err=x(:,n+1)-x(:,n);
if (norm(err,Inf) < tol)
%   
break;
end
fprintf('iteration %d %f %f %f \n',n,x(1,n),x(2,n), x(3,n));
  
  
end
x1=x(:,end);
end


Related Solutions

Write a C++ program to compare those two searching algorithms and also compare two sorting algorithms....
Write a C++ program to compare those two searching algorithms and also compare two sorting algorithms. You need to modify those codes in the book/slides to have some counters to count the number of comparisons and number of swaps. In the main function, you should have an ordered array of 120integers in order to test searching algorithms, and the other two identical arrays of 120integers not in order to test sorting algorithms. Display all counters in the main functions.Counter for...
Write a program to compare those two searching algorithms and also compare two sorting algorithms. You...
Write a program to compare those two searching algorithms and also compare two sorting algorithms. You need to modify those codes in the book/slides to have some counters to count the number of comparisons and number of swaps. In the main function, you should have an ordered array of 120 integers in order to test searching algorithms, and the other two identical arrays of 120integers not in order to test sorting algorithms. Display all counters in the main functions. Counter...
Using the bisection method:     Make a program to use this method using the following three...
Using the bisection method:     Make a program to use this method using the following three functions and use it to find the root of this function f (x) = x * x * x-8. a) A function so that the user between xlower and xupper that meets the value of the function has a different sign and if he does not ask for new values. b) A function to find the root and call it bisection and perform a...
Make the program(such as matlab) for solving the linear system Ax = b using the Naive-Gaussian...
Make the program(such as matlab) for solving the linear system Ax = b using the Naive-Gaussian elimination & also the Gaussian elimination with partial pivoting.
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of scalar nonlinear equa-tions. Use these programs to compute approximations to real roots of the following equations: exp(x)βˆ’3x^2=0, (1) x^3=x^2+x+1, (2) exp(x) =1/(0.1 +x^2), (3) and x= 1 + 0.3 cos(x). (4) Use an error tolerance tol=10^(βˆ’12). Display the obtained approximations to the roots of these equations, and compare the number of iterations, starting with the same initial values x0 for bisection and Newton methods,...
Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial...
Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial and Transcendental Functions.
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
using matlab Designing a program on ANY fractions Partial Show the two formals or figures in...
using matlab Designing a program on ANY fractions Partial Show the two formals or figures in time domin and z domin
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
Solve Kepler's Equations Using Euler's Method in matlab.
Solve Kepler's Equations Using Euler's Method in matlab.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT