Anda di halaman 1dari 2

BISECTION

clear
clc
x1=1;
x2=x1;
f1= x1^3+x1^2-3*x1-3;
h=1;
while h ; i=1
x2=x2+0.5;
f2=x2^3+x2^2-3*x2-3
t=f1*f2;
if t < 0
h=0;
else
h=1;
end
end
disp (' x1 x2 f1 f2')
[x1 x2 f1 f2]
h=1;
while h;
i=i+1
x3= (x1+x2)/2;
f3=x3^3+x3^2-3*x3-3;
t=1/2*abs(x1-x2);
if t<10^-5
h=0;
else
h=1;
if f3*f1<0
x2=x3;
f2=f3;
else
x1=x3;
f1=f3;
end
end
end
disp ('x1 x2 x3 error jumlah iterasi')
[ x1 x2 x3 t i]

Regulasi falsi
% regulafasi 9.34-21.97*x+16.3*x^2-3.704*x^3;
clear
clc
x1=input ('x1=');
x2=x1;
f1= 9.34-21.97*x1+16.3*x1^2-3.704*x1^3;
h=1;
while h
x2=x2+0.5;
f2=9.34-21.97*x2+16.3*x2^2-3.704*x2^3
t=f1*f2;
if t < 0

h=0;

else
end

h=1;

end
disp (' x1 x2 f1 f2')
[x1 x2 f1 f2]
h=1;
while h;
x3= x2-(f2/(f2-f1))*(x2-x1);
f3=9.34-21.97*x3+16.3*x3^2-3.704*x3^3;
if abs(f3) <10^-5
h=0;
else
h=1;
if f3*f1<0
x2=x3;
f2=f3;
else
x1=x3;
f1=f3;
end
end
end
disp ('x1 x2 x3 t')
[ x1 x2 x3 abs(f3) ]

Anda mungkin juga menyukai