Você está na página 1de 2

Gaussian Elimination of Matrix

A=[4 6 2;3 2 -6;5 -1 9]


B=[1; 2; 7]
Taking augumented matrix
for i=1 : 3
for j=1 : 3
Augment_Matrix(i,j)=A(i,j)
end
end
for k=1 : 3
Augment_Matrix(k,4)=B(k,1)
end
check=false
a=1
while(a~=4)
for i=1 : 3
if(Augment_Matrix(a,i)==0)% & Augment_Matrix(a,i)~=1)
continue
else
h=Augment_Matrix(a,i)
for g=i : 4-i
Augment_Matrix(a,:)=Augment_Matrix(a,:)*(h)
end
end
end
if(a<3)
for b=a+1 : 3
d=Augment_Matrix(b,a)
if(d>0)
Augment_Matrix(b,:)=Augment_Matrix(b,:)-d*Augment_Matrix(a,:)
else
Augment_Matrix(b,:)=Augment_Matrix(b,:)-d*Augment_Matrix(a,:)
end
end
else
Augment_Matrix(a,:)=Augment_Matrix(a,:)*(1/h)
end
a=a+1
end
Augment_Matrix
x
1=Augment_Matrix(1,1);
x2=Augment_Matrix(1,2);
x3=Augment_Matrix(1,3);
y1=Augment_Matrix(2,1);
y2=Augment_Matrix(2,2);
y3=Augment_Matrix(2,3);
z1=Augment_Matrix(3,1);
z2=Augment_Matrix(3,2);
z3=Augment_Matrix(3,3);
m=Augment_Matrix(1,4);
n=Augment_Matrix(2,4);
o=Augment_Matrix(3,4);
equation_1=strcat(int2str(x1) ,'x1',' + ',int2str(x2), 'x2 + ',int2str(x3),'x3 =
',int2str(m));
equation_1
equation_2=strcat(int2str(y1) ,'y1',' + ',int2str(y2), 'y2 + ',int2str(y3),'y3 =
',int2str(n));
equation_2
equation_3=strcat(int2str(z1) ,'z1',' + ',int2str(z2), 'z2 + ',int2str(z3),'z3 =

',int2str(o));
equation_3
code to calculate the value
z=o;
z
replace x3 and y3 with z
y=n+(-y3)*z;
replace x3 and y3 with z and x2 or y2 with y
x=m-y-2*z;
x
y
z
req_equation=strcat('Required equation is 'int2str(z1) ,'z1',' + ',int2s
tr(z2), 'z2 + ',int2str(z3),'z3 = ',int2str(o));

Você também pode gostar