Experiment 4:- Simultaneous Equations Matrix Method ( Gauss-Jordan Gauss Siedel Method )
Simultaneous Equations Matrix Method ( Gauss-Jordan Gauss Siedel Method )
CONCEPT :-
(a) (Gauss Elimination)
Briefly explain the theory of Gauss Elimination method for solving simultaneous equations.
(b)(Gauss Seidel)
Briefly explain the theory of Gauss Seidel method for solving simultaneous equations.
for theory click below;-
METHOD /CODE :-
(a) (Gauss Elimination)
Taking aii as the pivot element corresponding to i th row, we reduce all the rows Rk below the i th row by applying the row operation
Rk → Rk − (aik)/( aii) *Ri
It is to be noted that pivoting may be required in cases where some of the diagonal elements may assume zero value.
(b) (Backward Substitution)
The row reduced matrix would assume a triangular form (n = m) and the solution will then be obtained as given below
(c) (Gauss Seidel)
In many cases, the equations can be ordered in such a way the coefficient of xk in the k th equation is large in magnitude relative to all other coefficients in that equation and we can write
x1 = 1/a11*[b1 − a12*x2 − ... − a1n*xn] ,
x2 = 1/a22*[b2 − a21*x1 − ... − a2n*xn] . . .
xn = 1/ann*{bn − an1*x1 − ... − an(n−1)*xn−1}
The initial approximations may be taken to be x (0) i = bi/aii.
APPLICATIONS:-
We use these Methods to Solve Simultaneous Equations as Circuit Problems in Electricity and Magnetism.
Scilab Code For The Given Problem
Gauss Elimination Method code
clc,clear
function [x]=gauss(A,b)
[nA,mA]=size(A)
[nb,mb]=size(b)
if nA~=mA
disp("A should be a square matrix")
else if mA~=nb
disp("incompatible dimensions for gauss elimin ")
end
a=[A b]
//disp(a)
n=nA
//elimination
for k=1:n-1
for i=k+1:n
fact=a(i,k)/a(k,k)
a(i,:)=a(i,:)-(fact*a(k,:))
// disp(a)
end
end
// substitution
x(n)=a(n,n+1)/a(n,n)
for i=n-1:-1:1
sumk=0
for k=i+1:n
sumk=sumk+a(i,k)*x(k)
end
x(i)=(a(i,n+1)-sumk)/a(i,i)
end
end
disp(a,"Augmented matrix is")
disp(x,"The currents I1, I2 and I3 respectively are (in Amperes)")
disp("Current I1 is anticlockwise, Current I2 is clockwise, Current I3 is anticlockwise")
endfunction
A=[4,-1,0;-1,5,-1;0,1,-3]
b=[-1;2;1]
x=gauss(A,b)
Scilab Code for Gauss Siedel Method
//gauss seidel
clear, clc
a = [3 -2 0; 4 -13 3; 0 -3 18]
b = [4;0;1]
n=length(b)
for i = 1:n
j = 1:n;
j(i) = [];
B = abs(a(i,j));
//disp(sum(B))
if abs(a(i,i))<=sum(B)
disp("Matrix is not diagonally dominant")
end
end
tol=10^-4
iter=1
itmax=8
x=zeros(n,1)
k=1
xold=x
while k<=itmax
x(1)=(b(1)-a(1,2:n)*xold(2:n))/a(1,1)
for i=2:n-1
x(i)=(b(i)-a(i,1:i-1)*x(1:i-1)-a(i,i+1:n)*xold(i+1:n))/a(i,i)
end
x(n)=(b(n)-a(n,1:n-1)*x(1:n-1))/a(n,n)
if abs((x(i)-xold(i))/x(i))<tol
disp(x-xold)
break
end
xold=x
k=k+1
iter=iter+1
end
disp(x(1),"Current I1 (in Amperes) is = ")
disp(x(2),"Current I2 (in Amperes) is = ")
disp(x(3),"Current I3 (in Amperes) is = ")
disp(iter,"Number of iterations are")
Note :- First Solve the Problem and Make simultaneous Equations after it sattel them in a Form of Matrix and verify them Theoretically .
If you have any Problem or Query Regarding this Blog Please Comment Down Or Reach us Out at scilabprogram@gmail.com
//university of Delhi //Department of Physics
Comments
Post a Comment