Gauss Seidel

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Practical 7:- Gauss-Seidel

Q) Solve the system of equation by gauss-siedel method with


initial condition X H0L=0.
2 X1 - X2 = -1
-1 X1 + 4X2 + 2X3 = 3
2 X2 + 6 X3 = 5

Mathematica command : -

GaussSeidel@A0_, B0_, P0_, max_D := ModuleB


8A = N@A0D, B = N@B0D, i, j, k = 0, n = Length@P0D, P = P0<,
Print@" P "0 , " = ", PD;
WhileBk < max,

ForBi = 1, i £ n, i ++,

P@@iDD = 1  A@@i, iDD B@@iDD + A@@i, iDD * P@@iDD - â A@@i, jDD * P@@jDD F;
n

j=1

Print@" P "k+1 , " = ", PD;


k = k + 1;F;

Return@pD;F;
2 -1 0
A= -1 4 2 ;
0 2 6
B = 8- 1, 3, 5<;
vars = 8"X1", "X2", "X3"<;
Print@"Solve the system"D;
Print@MatrixForm@AD, MatrixForm@varsD, "=", MatrixForm@BDD
Solve the system

2 -1 0 X1 -1
-1 4 2 X2 = 3
0 2 6 X3 5

P = 80, 0, 0<;
X = GaussSeidel@A, B, P, 2D;
Print@" AX = ", MatrixForm@A.XD, " » ", MatrixForm@BD, " =B "D;
2 gauss-seidel.nb

P 0 = 80, 0, 0<

P 1 = 8- 0.5, 0.625, 0.625<

P 2 = 8- 0.1875, 0.390625, 0.703125<

0 -1
AX = 13 » 3 =B
22 5

You might also like