[go: up one dir, main page]

0% found this document useful (0 votes)
16 views2 pages

P4

The document outlines the implementation of the Gauss elimination and Gauss-Jordan methods for solving linear equations, demonstrating matrix manipulation and back substitution. It also covers the Gauss-Jacobi and Gauss-Seidel methods, including checks for diagonal dominance and iterative solutions based on initial guesses. The code provided includes matrix definitions, iterations, and convergence criteria for the iterative methods.
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)
16 views2 pages

P4

The document outlines the implementation of the Gauss elimination and Gauss-Jordan methods for solving linear equations, demonstrating matrix manipulation and back substitution. It also covers the Gauss-Jacobi and Gauss-Seidel methods, including checks for diagonal dominance and iterative solutions based on initial guesses. The code provided includes matrix definitions, iterations, and convergence criteria for the iterative methods.
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/ 2

//gauss elimination method and gauss jordan method

clc; clear;
a=[12 3 -5; 1 5 3; 3 7 13]
b=[1;28;76]
n=length(b)
a=[a b]
disp(a)
for j=1:n-1. // for j=1:n
//a(j,:)=a(j,:)/a(j,j) remove //
for i=j+1:n //for i=1:n
if i~=j
m=a(i,j)/a(j,j)
a(i,:)=a(i,:)-(m*a(j,:))
end
//disp(a)
end
disp(a)
end
x=zeros(1,n)
for i=n:-1:1
ax=sum(a(i,1:n).*x)
x(i)=(a(i,n+1)-ax)/a(i,i)
disp('x('+string(i)+')='+string(x(i)))
end
// gauss Jacobi method and gauss siedel method
a=[3 -1 1;-1 4 1;-1 1 5]
b=[20;6;7]
n=length(b)
c=0
for i=1:n
s=0
for j=1:n
if j~=i
s=s+a(i,j)
end
end
if (a(i,i)>s)
c=c+1
else break
end
end
if c==n then
disp('matrix is diagonally dominant')
else
disp('matrix is diagonally not dominant')
end
x=input('Initial guess of first value ');
y=input('Initial guess of second value ');
z=input('initial guess of third value ');
n=input('Enter no. of iterations ')
for i=1:n
x(i+1)=(b(1,1)-(a(1,2)*y(i))-(a(1,3)*z(i)))/a(1,1)
y(i+1)=(b(2,1)-a(2,1)*x(i)-a(2,3)*z(i))/a(2,2)
z(i+1)=(b(3,1)-a(3,1)*x(i)-a(3,2)*y(i))/a(3,3)
if (abs(x(i+1)-(x(i)))<0.0001)& (abs(y(i+1)-(y(i)))<0.0001) &
(abs(z(i+1)-(z(i)))<0.0001)
break
end
end
disp("No. of iteration",i,x(i),y(i),z(i))

You might also like