You can use point jacobi or gauss siedel to solve this problem. Write a function
ID: 2995352 • Letter: Y
Question
You can use point jacobi or gauss siedel to solve this problem.
Write a function that implements a Point-Jacobi iterative method to solve for the solution to the system of equations Ax = b. Your function should accept the input matrix A, right-hand-side vector b, the initial solution guess x0 and maximum approximate relative error || epsilon a || infinity as arguments, and return the value of the solution vector xi as its output. You can use MATLAB, C, C++ or Fortran to code the solution to this problem. You will receive zero credit if you use a built-in linear algebra function to compute the solution to the system. In MATLAB, your function declaration should look something like this:Explanation / Answer
function x_i =pointjacobi(A,b,x_0,eps_a_max);
format compact
n = length(b);
Error_eval = ones(n,1);
%% Check if the matrix A is diagonally dominant
for i = 1:n
j = 1:n;
j(i) = [];
B = abs(A(i,j));
Check(i) = abs(A(i,i)) - sum(B); % Is the diagonal value greater than the remaining row values combined?
if Check(i) < 0
fprintf('The matrix is not strictly diagonally dominant at row %2i ',i)
end
end
%% Start the Iterative method
iteration = 0;
while max(Error_eval) > eps_a_max
iteration = iteration + 1;
Z = x_0; % save current values to calculate error later
for i = 1:n
j = 1:n; % define an array of the coefficients' elements
j(i) = []; % eliminate the unknow's coefficient from the remaining coefficients
Xtemp = x_0; % copy the unknows to a new variable
Xtemp(i) = []; % eliminate the unknown under question from the set of values
x_0(i) = (b(i) - sum(A(i,j) * Xtemp)) / A(i,i);
end
Xsolution(:,iteration) = x_0;
Error_eval = sqrt((x_0 - Z).^2);
end
x_i=Xsolution(:,iteration);
% sample input
% A = [-6 2 1 2 1;
% 3 8 -4 1 0;
% -1 1 4 10 1;
% 3 -4 1 9 2;
% 2 0 1 3 10];% coefficients matrix
% b = [3;4;-2 ;12;1];% constants vector
% n = length(b);
% x_0 = zeros(n,1);
% eps_a_max=0.001;
% pointjacobi(A,b,x_0,eps_a_max)
%output:
%
% x_i =
% -1.1222
% -1.3887
% -4.2461
% 1.4952
% 0.3005
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.