using Gauss Jacobi method to solve a system of equations

192 views (last 30 days)
I'm new to Matlab so don't have the best understanding here, i need to use the jacobi method to find the values of C but i dont really know the code that i need to use.
My equations are:
(837*C3)/2000 - (6851*C2)/10000 - (1091*C1)/2500 - (821*C4)/2000
(1337*C1)/2000 + (437*C2)/2500 + (3899*C3)/10000 - (6087*C4)/10000
(1601*C2)/2500 - (2939*C1)/5000 - (477*C3)/10000 - (4921*C4)/10000
(1313*C1)/10000 - (3*C2)/10 - (8209*C3)/10000 - (292*C4)/625
A = [-0.4364 -0.6851 0.4185 -0.4105; 0.6685 0.1748 0.3899 -0.6087; -0.5878 0.6404 -0.0477 -0.4921; 0.1313 -0.3000 -0.8209 -0.4672];
B = [0;40;0;0];
please note that this is not diaganally dominant but ive been told to do it anyway - it is part of an assignment.
cheers.

Answers (1)

Vidhi Agarwal
Vidhi Agarwal on 9 Jun 2023
To solve Ax = B using Gauss-Jacobi method, we need to first transform the system of equations into an iterative form, as follows:
x1(k+1) = ( B1 - A12*x2(k) - A13*x3(k) - A14*x4(k) ) / A11
x2(k+1) = ( B2 - A21*x1(k) - A23*x3(k) - A24*x4(k) ) / A22
x3(k+1) = ( B3 - A31*x1(k) - A32*x2(k) - A34*x4(k) ) / A33
x4(k+1) = ( B4 - A41*x1(k) - A42*x2(k) - A43*x3(k) ) / A44
where x1(k), x2(k), x3(k), and x4(k) are the current approximations of the solution, and x1(k+1), x2(k+1), x3(k+1), and x4(k+1) are the next approximations of the solution.
We can start the iteration with an initial guess for the values of x1(k), x2(k), x3(k), and x4(k). Let's choose x1(0) = x2(0) = x3(0) = x4(0) = 0 as our initial guess.
Then, we can plug in the values of x1(0), x2(0), x3(0), and x4(0) into the iterative equations to obtain the next approximations of the solution, as follows:
Here's the Implementation of Jacobi Method:
A = [-0.4364 -0.6851 0.4185 -0.4105; 0.6685 0.1748 0.3899 -0.6087; -0.5878 0.6404 -0.0477 -0.4921; 0.1313 -0.3000 -0.8209 -0.4672];
B = [0;40;0;0];
% Set the initial guess for the solution values
x0 = [0;0;0;0];
% Set the maximum number of iterations
max_iter = 100;
% Set the convergence criteria
tolerance = 1e-6;
% Perform Gauss-Jacobi iteration
x = x0;
for i = 1:max_iter
x_old = x;
for j = 1:length(B)
x(j) = (B(j) - sum(A(j,:) .* x_old) + A(j,j)*x_old(j)) / A(j,j);
end
% Check for convergence
if norm(x - x_old) < tolerance
fprintf('Solution converged after %d iterations\n', i);
break;
end
end
% Display the solution vector x
fprintf('Solution:\n');
disp(x);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!