请问怎么用matlab编程,使用牛顿迭代法求根号5的立方的近似值???

2025-05-16 23:14:27
推荐回答(1个)
回答(1):

1.
创建一个函数
%牛顿法求立方根
function
x=cube_newton(a)
f=@(x)x^3-a;
df=diff(sym('x^3-a'));
if
a==0;
x1=a;
else
x0=a;
x1=x0-f(x0)/subs(df,x0);
while
abs(x1-x0)>1e-6
x0=x1;
x1=x0-f(x0)/subs(df,x0);
end
end
x=x1;
2.
调用求解
>>
a=cube_newton(5)
a
=
1.7100
>>