-2
:二分法:ない十分な入力エラー、私は二分法のために、次のコードを書いた
f1=input('Enter the equation:','s');
f=inline(f1);
e1=input('Enter the first end:');
e2=input('Enter the first end:');
acc=input('Enter the accuracy:');
disp('*******************************');
m=(e1+e2)/2;
i=0;
while abs(f(m))>acc
i=i+1;
fprintf('%d)\t%f\tf(x)=%f\n',i,m,f(m));
if (f(m)*f(e2))<0
e1=m;
else
e2=m;
end
m=(e1+e2)/2;
end
fprintf('%d)\t%f\tf(x)=%f\n',i,m,f(m));
disp ('************************');
fprintf('The root of equation by bisection method (Accuracy Type) = %f\n',m);
これは、いくつかの単純な方程式(例; x^2-6
)のために動作しますが、それは次のように複雑な方程式では動作しません。e-x(3.2 sin(x) - 0.5 cos(x))
区間[3, 4]
にあります。 私は、次のエラーを取得しています: