> 数学 >
用二分法求方程x^3-2x-3=0在区间[1,2]内一个近似解的算法伪代码(误差不超过0.001)
人气:384 ℃ 时间:2020-04-12 17:28:36
解答
small = 0.001
def f(x):
return x*x*x-2*x-3
def calc(x1,x2):
xmid = (x1 + x2)/2
ymid = f(xmid)
if (ymid < -small) :
result = calc(xmid,x2)
else if (ymid > small) :
result = calc(x1,xmid)
else :
result = xmid
return result
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版