Question: Develop a computer program to solve the following system of equations ( employ initial guesses of 0 . 0 for all unknowns ) : -

Develop a computer program to solve the following system of equations
(
employ initial guesses of
0.0
for all
unknowns
)
:
-
j
-
2
k
+
4
l
-
2
m
=
97.54
j
-
3
k
+
2
l
-
n
=
79.75
2
k
-
3
l
+
6
m
=
102.28
3
j
+
l
-
2
m
+
7
n
=
84.49
-
3
j
-
k
+
m
-
2
n
=
102.37
using the following two methods:
(
a
)
Gauss
-
Seidel
(
b
)
Jacobi
Perform iterations until the approximation error is
<
0.00001
and then comment on the obtained results.
Please follow the below given details and i need the exact solution of the problem.
IMP Note:
For this problem, it is mandatory to use MatLab. However, you are not allowed to use any built in functions in MatLab that are not available in the other compilers.
Below is the code given to me but not getting the output. resolve it.
% Given system of equations
A =[-1-24-20;
1-32-10;
02-360;
31-270;
-3-110-2];
b =[97.54; 79.75; 102.28; 84.49; 102.37];
% Initial guess
x0=[0; 0; 0; 0; 0];
% Gauss-Seidel Method
disp('Gauss-Seidel Method:');
[x_gs, iterations_gs]= gaussSeidel(A, b, x0,0.000001);
disp(['Solution after ', num2str(iterations_gs),' iterations:']);
disp(x_gs);
% Jacobi Method
disp('Jacobi Method:');
[x_jacobi, iterations_jacobi]= jacobi(A, b, x0,0.000001);
disp(['Solution after ', num2str(iterations_jacobi),' iterations:']);
disp(x_jacobi);
% Gauss-Seidel method function
function [x, iterations]= gaussSeidel(A, b, x0, tolerance)
n = length(b);
x = x0;
x_prev = x0+2*tolerance; % to enter the while loop
iterations =0;
while norm(x - x_prev, inf)> tolerance
x_prev = x;
for i =1:n
x(i)=(b(i)- A(i,1:i-1)*x(1:i-1)- A(i,i+1:n)*x_prev(i+1:n))/ A(i,i);
end
iterations = iterations +1;
end
end
% Jacobi method function
function [x, iterations]= jacobi(A, b, x0, tolerance)
n = length(b);
x = x0;
x_prev = x0+2*tolerance; % to enter the while loop
iterations =0;
while norm(x - x_prev, inf)> tolerance
x_prev = x;
for i =1:n
x(i)=(b(i)- A(i,:)* x_prev + A(i,i)* x_prev(i))/ A(i,i);
end
iterations = iterations +1;
end
end.
MIMP : Gauss-Seidel Method:
Unrecognized function or variable 'gaussSeidel'. I want the solution of this error and give me proper code along eith proper iterations showing each and every steps.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!