新手练习,仅能求解该函数,若要求解其它函数需要手动在代码中替换
x1=1;
x2=1.5;
eps=0.005;
x=(x1+x2)/2;
eps2=(x2-x1)/2;
while eps2>eps
if (x^3-x-1)<0
x1=x;
else (x^3-x-1)>0
x2=x;
end
eps2=(x2-x1)/2;
x=(x1+x2)/2;
end
x
新手练习,仅能求解该函数,若要求解其它函数需要手动在代码中替换
x1=1;
x2=1.5;
eps=0.005;
x=(x1+x2)/2;
eps2=(x2-x1)/2;
while eps2>eps
if (x^3-x-1)<0
x1=x;
else (x^3-x-1)>0
x2=x;
end
eps2=(x2-x1)/2;
x=(x1+x2)/2;
end
x