Switch Case: %program Nomer 2, Alfi Tae
Switch Case: %program Nomer 2, Alfi Tae
clear all;
clc;
disp('choose a method');
disp('1. Gauss Jordan');
disp('2. Jacobi');
disp('3. Siedel');
a=input('choose one=');
switch a
case 1
disp('gauss jordan');
disp('GAUSS JORDAN');
f1=input('Equation 1:');
f2=input('Equation 2:');
f3=input('Equation 3:');
f0=[f1;f2;f3]
a1=f1(1,:)/f1(1,1);
a2=f2(1,:)-(f2(1,1)*a1);
a3=f3(1,:)-(f3(1,1)*a1);
f4=[a1;a2;a3]
b2=a2(1,:)/a2(1,2);
b1=a1(1,:)-(a1(1,2)*b2);
b3=a3(1,:)-(a3(1,2)*b2);
f5=[b1;b2;b3]
c3=b3(1,:)/b3(1,3);
c1=b1(1,:)-(b1(1,3)*c3);
c2=b2(1,:)-(b2(1,3)*c3);
f6=[c1;c2;c3]
disp('Final result:');
disp([f0]);
disp('as the following:');
disp(['value of x:',num2str(abs(c1(1,4)))]);
disp(['value of y:',num2str(abs(c2(1,4)))]);
disp(['value of z:',num2str(abs(c3(1,4)))]);
%d itu nilai yang ada di D, yang ada di nilai z
d=input('aye bitches, input the diameter value= ');
%x1 itu nilai yang ada square d dikali dengan height
tinggi=d/2;
disp(['nilai diameter',num2str(d,'%2.2f')]);
disp(['tinggi=',num2str(tinggi,'%2.2f')]);
case 3
%input the value of correction in range of 1 to 5
disp('siedel');
a=input('Equation 1:');
b=input('Equation 2:');
c=input('Equation 3:');
eror=input('Input percent of error:');
y=0;
z=0;
x1=(a(1,4)-a(1,2)*y-a(1,3)*z)/a(1,1);
y1=(c(1,4)-b(1,1)*x1-b(1,3)*z)/b(1,2);
z1=(c(1,4)-c(1,1)*x1-c(1,2)*y*y1)/c(1,3);
epx=100;
epy=100;
epz=100;
it=1;
fprintf('------------------------------------------------------------
------------\n');
fprintf('%2s%8s%10s%11s%14s%11s%11s\n','it','D^2.H','D^3','D','errorx','error
y','errorz');
fprintf('------------------------------------------------------------
------------\n');
fprintf('%2.0f%10.4g%11.4g%11.4g%11.4f%11.4f%11.4f\n',it,x1,y1,z1,epx,epy,epz
);
while (epx>eror)&&(epy>eror)&&(epz>eror);
x=x1;
y=y1;
z=z1;
x1=(a(1,4)-a(1,2)*y-a(1,3)*z)/a(1,1);
y1=(c(1,4)-b(1,1)*x1-b(1,3)*z)/b(1,2);
z1=(c(1,4)-c(1,1)*x1-c(1,2)*y*y1)/c(1,3);
epx=abs((x1-x)/x1)*100;
epy=abs((y1-y)/y1)*100;
epz=abs((z1-z)/z1)*100;
it=it+1;
fprintf('%2.0f%10.4g%11.4g%11.4g%11.4f%11.4f%11.4f\n',it,x1,y1,z1,epx,epy,epz
);
end
%d itu nilai yang ada di D, yang ada di persamaan z
d=input('aye bitches, input the diameter value= ');
tinggi=d/2;
disp(['nilai diameter',num2str(d,'%2.2f')]);
disp(['tinggi=',num2str(tinggi,'%2.2f')]);
case 2
%input the value of correction in range of 5 to 10
disp('jacobi');
a=input('Equation 1:');
b=input('Equation 2:');
c=input('Equation 3:');
eror=input('Input percent of error:');
x=0;
y=0;
z=0;
x1=(a(1,4)-a(1,2)*y-a(1,3)*z)/a(1,1);
y1=(c(1,4)-b(1,1)*x-b(1,3)*z)/b(1,2);
z1=(c(1,4)-c(1,1)*x-c(1,2)*y)/c(1,3);
epx=100;
it=1;
fprintf('--------------------------------------------------------
------\n');
fprintf('%2s%8s%10s%11s%14s\n','i','D^2.H','D^3','D','erorx');
fprintf('--------------------------------------------------------
------\n');
fprintf('%2.0f%10.g%11.4g%11.4g%11.4f\n',it,x1,y1,z1,epx);
while epx>eror;
x=x1;
y=y1;
z=z1;
x1=(a(1,4)-a(1,2)*y-a(1,3)*z)/a(1,1);
y1=(c(1,4)-b(1,1)*x1-b(1,3)*z)/b(1,2);
z1=(c(1,4)-c(1,1)*x1-c(1,2)*y)/c(1,3);
epx=abs((x1-x)/x1)*100;
it=it+1;
fprintf('%2.0f%10.4g%11.4g%11.4g%11.4f\n',it,x1,y1,z1,epx);
%d itu nilai yang ada di D, yang ada di persamaan z
d=input('aye bitches, input the diameter value= ');
tinggi=d/2;
disp(['nilai diameter',num2str(d,'%2.2f')]);
disp(['tinggi=',num2str(tinggi,'%2.2f')]);
end
end