Write a MatLab program to find the value of ×, y and z using Gauss-Elimination method in
the following equations
2x+4y + 2 - 3;
3x+2y - 2z= -2;
x-y+z=6.
%Gauss elimination method [m,n)=size(a);
a=[2 4 2 3
3 2 -2 2
1 -1 1 6];
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==0
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end
disp('Gauss elimination method:');
a
x'
Result:
ans =
2.8000
-1.5000
1.7000
>>
Comments
Leave a comment