0% found this document useful (0 votes)
3 views

Numerical 06(Urmi)

The document outlines an experiment focused on solving systems of linear equations using the Jacobi and Gauss-Seidel methods in MATLAB. It details the objectives, theoretical background, algorithms, MATLAB code, and outputs for both methods, highlighting that the Gauss-Seidel method generally converges faster due to its use of updated values during iterations. The experiment emphasizes the practical application and efficiency of these iterative methods in numerical analysis.

Uploaded by

Eo Sanam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Numerical 06(Urmi)

The document outlines an experiment focused on solving systems of linear equations using the Jacobi and Gauss-Seidel methods in MATLAB. It details the objectives, theoretical background, algorithms, MATLAB code, and outputs for both methods, highlighting that the Gauss-Seidel method generally converges faster due to its use of updated values during iterations. The experiment emphasizes the practical application and efficiency of these iterative methods in numerical analysis.

Uploaded by

Eo Sanam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

6.

1 Experiment No: 06
6.2 Name of the Experiment : Solving system of linear equations using Jacobi and Gauss-Seidel
Method

6.3 Objectives:
1. To implement Jacobi and Gauss-Seidel methods in MATLAB
2. To compare the performance and efficiency of the Jacobi and Gauss-Seidel methods.
6.4 Theory:

The Jacobi method is an iterative technique used to solve a system of linear equations. It starts
with an initial guess for all variables and updates each variable in the system using only the
values from the previous iteration. This means that during an iteration, none of the new values
are used until the next round. The method is simple and easy to implement, but it may take more
iterations to converge, especially if the system is not diagonally dominant or well-conditioned.

The Gauss-Seidel method is another iterative approach for solving linear equations, but it
improves efficiency by using the latest updated values as soon as they are computed. Unlike the
Jacobi method, it replaces the old values with the new ones during the same iteration, leading to
faster convergence in many cases. This method is particularly effective for systems that are
diagonally dominant or symmetric positive definite, and it generally requires fewer iterations to
reach the desired accuracy.

While both the Jacobi and Gauss-Seidel methods are used for solving linear systems iteratively,
the main difference lies in how they update values. The Jacobi method uses only old values in
each iteration, making it simpler but slower. The Gauss-Seidel method uses updated values
within the same iteration, leading to faster convergence. However, both methods require careful
checking for convergence conditions, and their performance can vary depending on the nature of
the system.

We will use this approach to resolve the following system of linear equations:

3x1 -0.1x2 -0.2x3=7.85;

0.1x1 + 7x2 -0.3x3 =-19.3;

0.3x1 -0.2x2 + 10x3 =71.4

6.5 Algorithm:

6.5.1 Jacobi Method:

1
Step 1: Start
Step 2: Arrange given system of linear equations in diagonally dominant form
Step 3: Read tolerable error (e)
Step 4: Convert the first equation in terms of first variable, second equation in terms of second
variable and so on.
Step 5: Set initial guesses for x0, y0, z0 and so on
Step 6: Substitute value of x0, y0, z0 ... from step 5 in equation obtained in step 4 to calculate
new values x1, y1, z1 and so on
Step 7: If| x0 - x1| > e and | y0 - y1| > e and | z0 - z1| > e and so on then goto step 9
Step 8: Set x0=x1, y0=y1, z0=z1 and so on and goto step 6
Step 9: Print value of x1, y1, z1 and so on
Step 10: Stop

Gauss Seidel Method:


Step 1: Start.
Step 2: Arrange given system of linear equations in a diagonally dominant form
Step 3: Read tolerable error (e)
Step 4: Convert the first equation in terms of first variable, second equation in terms of second
variable and so on.
Step 5: Set initial guesses for X0, Y0, Z0 and so on
Step 6: Substitute value of Y0, Z0 ... from step 5 in first equation obtained from step 4 to calculate
new value of X1. Use X1, Z0, U0 in second equation obtained from step 4 to calculate new value of
Y1. Similarly, use X1, Y1, U0 to find new Z1 and so on.
Step 7: If| x0 - x1| > e and | y0 - y1| > e and | z0 - z1| > e and so on then goto step 9
Step 8: Set x0=x1, y0=y1, z0=z1 and so on and goto step 6
Step 9: Print value of x1, y1, z1 and so on
Step 10: Stop

2
6.5 MATLAB Code :
6.5.1 Jacobi Method:
clc;
clear;
A=[3 -0.1 -0.2;
0.1 7 -0.3;
0.3 -0.2 10];
b=[7.85;-19.3;71.4];
x = [0; 0; 0];
tol = 1e-5;
maxIter = 100;
x_old = x;
for k = 1:maxIter
for i = 1:3
sum = 0;
for j = 1:3
if j ~= i
sum = sum + A(i,j) * x_old(j);
end
end
x(i) = (b(i) - sum) / A(i,i);
end
fprintf('Iteration %d: x = [%f %f %f]\n', k, x(1),
x(2), x(3));
if norm(x - x_old, inf) < tol
fprintf('Gauss-Jacobi method converged in %d
iterations.\n', k);
break;
end
x_old = x;
end
disp('Final Solution using Gauss-Jacobi Method:')
disp(x)

6.5.2 Gauss Seidel Method:


clc;
clear;
A=[3 -0.1 -0.2;
0.1 7 -0.3;
0.3 -0.2 10];

3
b=[7.85;-19.3;71.4];
x = [0; 0; 0];
tol = 1e-5;
maxIter = 100;

for k = 1:maxIter
x_old = x;
for i = 1:3
sum = 0;
for j = 1:3
if j ~= i
sum = sum + A(i,j) * x(j);
end
end
x(i) = (b(i) - sum) / A(i,i);
end
fprintf('Iteration %d: x = [%f %f %f]\n', k, x(1),
x(2), x(3));
if norm(x - x_old, inf) < tol
fprintf('Gauss-Seidel method converged in %d
iterations.\n', k);
break;
end
end

disp('Final Solution using Gauss-Seidel Method:')


disp(x)

6.6 Output:
6.6.1 Output for Jacobi Method:

Iteration 1: x = [2.616667 -2.757143 7.140000]


Iteration 2: x = [3.000762 -2.488524 7.006357]
Iteration 3: x = [3.000806 -2.499738 7.000207]
Iteration 4: x = [3.000022 -2.500003 6.999981]
Iteration 5: x = [2.999999 -2.500001 6.999999]
Iteration 6: x = [3.000000 -2.500000 7.000000]
Gauss-Jacobi method converged in 6 iterations.
Final Solution using Gauss-Jacobi Method:
3.0000
-2.5000
7.0000
6.6.2 Output for Gauss Seidel Method:
Iteration 1: x = [2.616667 -2.794524 7.005610]

4
Iteration 2: x = [2.990557 -2.499625 7.000291]
Iteration 3: x = [3.000032 -2.499988 6.999999]
Iteration 4: x = [3.000000 -2.500000 7.000000]
Iteration 5: x = [3.000000 -2.500000 7.000000]
Gauss-Seidel method converged in 5 iterations.
Final Solution using Gauss-Seidel Method:
3.0000
-2.5000
7.0000
6.7 Discussion:
In this experiment, we solved a system of linear equations using the Jacobi and Gauss-Seidel
iterative methods. Both methods are used to find approximate solutions, especially for large
systems where direct methods are difficult. We started with an initial guess and updated the values
in each iteration until the solution converged within a set tolerance. The Gauss-Seidel method
generally converged faster because it uses updated values immediately, while the Jacobi method
uses old values for all calculations in an iteration. This experiment helped us understand the
efficiency, accuracy, and practical use of iterative methods in numerical analysis.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy