Created
November 26, 2022 00:41
-
-
Save iqlal/c5f8979ea900a207e24611a9ec7b10a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [4 2 1 1; 1 -1 3 20; 2 1 1 3]; | |
[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('Cara Gauss:'); | |
a | |
[m,n]=size(a); | |
for j=1:m-1 | |
for z=2:m | |
if a(j,j)==0 | |
t=a(1,:);a(1,:)=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 | |
for j=m:-1:2 | |
for i=j-1:-1:1 | |
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j)); | |
end | |
end | |
for s=1:m | |
a(s,:)=a(s,:)/a(s,s); | |
x(s)=a(s,n); | |
end | |
disp('Cara Gauss jordan:'); | |
a | |
x = a(3,4) | |
y = a(2,4) | |
z = a(1,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment