METODE
BISECTION
clc;
disp('----------------------------------')
disp('Program : METODE
BISECTION ')
disp('Programer : MUHAMMAD MUNIR ')
disp('----------------------------------')
f=input('f(x)= ');
x1=input('x1= ');
x2=input('x2= ');
a=input('toleransi= ');
if f(x1)*f(x2)>0
disp(['pilih ulang X1 dan X2'])
x1=input('x1= ');
x2=input('x2= ');
end
c=0;
x=0.5*(x1+x2);
while abs(f(x))>a
c=c+1;
x=0.5*(x1+x2);
if f(x1)*f(x)>0
x1=x;
else if
f(x1)*f(x)<0
x2=x;
end
end
disp(['iterasi ke- '
num2str(c)]);
disp(['x = '
num2str(x), 'dengan f(x) = ' num2str(f(x))]);
disp(['x1= '
num2str(x1), 'dengan f(x1) = ' num2str(f(x1))]);
disp(['x2= '
num2str(x2), 'dengan f(x2) = ' num2str(f(x2))]);
end
disp(['jadi nilai x = ' num2str(x), 'dengan
f(x) = ' num2str(f(x))]);
SCANT
clc;
disp('----------------------------------')
disp('Program : SCANT ')
disp('Programer : MUHAMMAD MUNIR ')
disp('----------------------------------')
f=input('f(x) =');
E=input('Toleransi error =');
c=2;
x(c-1)=input('x0 =');
x(c)=input('x1 =');
disp(['x0='
num2str(x(c-1)),' ','dengan
f(X0)=' num2str(f(x(c-1)))])
disp(['x1='
num2str(x(c)),' ','dengan
f(X1)=' num2str(f(x(c)))])
disp(['iterasi ke -' ,num2str(c-1)]);
x(c+1)=x(c)-(((f(x(c))).*((x(c)-x(c-1))))./((f(x(c)))-((f(x(c-1))))));
disp(['x = ' num2str(x(c+1)),' ', 'dengan
f(x)) =' num2str(f(x(c+1)))]);
while abs(f(x(c+1)))>E;
c=c+1;
disp(['iterasi ke -',num2str(c-1)])
x(c+1)=x(c)-(((f(x(c))).*((x(c)-x(c-1))))./((f(x(c)))-((f(x(c-1))))));
disp(['x = '
num2str(x(c+1)), ' ','dengan
f(x)) =' num2str(f(x(c+1)))]);
end
REGULA
FAALSI
clc;
disp('----------------------------------')
disp('Program : REGULA
FALSI ')
disp('Programer : MUHAMMAD MUNIR ')
disp('----------------------------------')
f= input('f(x) =');
E= input (' Toleransi error =');
x1= input('x1 =');
x2= input('x2 =');
f(x1);,f(x2);
disp(['f(x1)=',num2str(f(x1)), '
dan f(x2)=',num2str(f(x2))]);
if f(x1)*f(x2)>0;
disp(['oww salaaah..... x1 dan x2,coba lgi skli,ambil sembrang x1 dan
x2']);
x1=input('x1 =');
x2=input('x2 =');
f(x1);,f(x2);
disp(['f(x1) =',num2str(f(x1)),
'dan f(x2) =',num2str(f(x2))]);
end
c=0;
xr=x1+((x2-x1)*f(x1)/f(x1)-f(x2));
while abs(f(xr))>E;
c=c+1;
disp(['Iterasi ke-',num2str(c)])
xr=x1+[((x2-x1)*f(x1))/(f(x1)-f(x2))];
disp(['x =',num2str(xr),
' dengan f(x) =',num2str(f(xr))]);
if f(x1)*f(xr)<0;
x2=xr;
disp(['f(x)f(x1) =',num2str(f(xr)*f(x1))]);
disp(['x1 =',num2str(x1),
' dan x2_baru =',num2str(xr)]);
elseif f(xr)*f(x1)>0;
x1=xr;
disp(['f(x)f(x1) =',num2str(f(xr)*f(x1))]);
disp(['x1_baru =',num2str(xr),
'dan x2_baru =',num2str(x2)]);
end
end
disp(['jadi x =',num2str(xr), '
dengan f(x) =',num2str(f(xr))])
NEWTON RAPSON
clc;
disp('----------------------------------')
disp('Program : NEWTON
RAPSON ')
disp('Programer : MUHAMMAD MUNIR ')
disp('----------------------------------')
f1=input('f(x) =');
f2=input('df(x) =');
x=input('x0 =');
while f2(x)==0
disp(['maaf pilihan anda kurang tepat,,,,,, coba pilih ulang sampai
df(x) ~= 0'])
x=input('x0 =');
end
a=input('toleransi kesalahan =');
b=0;%persiapan mencatat iteraasi
while abs(f1(x))>a
b=b+1;%mencatat iterasi
disp(['itreasi ke--->' num2str(b)])
x=x-(f1(x)./f2(x));
disp(['x ='
num2str(x)])
disp(['f(x) ='
num2str(f1(x))])
disp(['df(x) ='
num2str(f2(x))])
end
disp(['akar persamaan adalah x=' num2str(x) 'dengan f(x)='
num2str(f1(x))])
FIXET POINT
clear all;
clc;
disp('----------------------------------')
disp('Program :
Iterasi Sederhana ')
disp('Programer : MUHAMMAD MUNIR ')
disp('----------------------------------')
f=input('f(x) = ');
g=input('g(x) = ');
x=input('x_awal = ');
E=input('Toleransi Error = ');
disp('________________________________')
c=0;
while abs(f(x))>E
c=c+1;
disp(['Iterasi ke- '
num2str(c)])
x=g(x);
disp(['x = ',num2str(x) 'g(x) = ',num2str(g(x))])
disp(['f(x) = '
num2str(f(x))])
disp(' ')
end
Tidak ada komentar:
Posting Komentar