運行下面簡單的程序,二分法求方程的根,調(diào)試的時候在循環(huán)處設(shè)斷點,繼續(xù)系統(tǒng)就退出了,直接運行沒有問題
clc;clear all
f=@(x)sin(x);
a=-1;
b=pi/2;
e=1e-8;
k=100;
a0=a;
b0=b;
x=(a0+b0)/2.0;
fa = f(a);
fb = f(b);
fx=f(x);
while(abs(fx) > eps)
if (sign(fx)*sign(fa) < 0)
b0 = x;
fb = fx;
else
a0 = x;
fa = fx;
end
x = (a0+b0)/2.0;
fx=f(x);
end