编写程序,用牛顿切线法求方程f(x)= x+lnx-1.7=0的近似实根r, 迭代初值自选,精确到0.0001。〔提示:计算

2024-12-03 05:43:05
推荐回答(2个)
回答(1):

程序;
clear
clc
syms x
f=(x+log(x)-1.7).^2;
eps=1;x0=1;
df=diff(f,x);
dff=diff(df,x);
while abs(eps)>1e-4
df1=subs(df,x,x0);
dff2=subs(dff,x,x0);
if dff2==0
break
else
xx=x0-(1/dff2)*df1;
end
eps=xx-x0;x0=xx;
end
x0
min=subs(f,x,x0)
运行结果:
x0 =
1.3788
min =
2.5738e-022

回答(2):

程序;
clear
clc
syms x
f=(x+log(x)-1.7).^2;
eps=1;x0=1;
df=diff(f,x);
dff=diff(df,x);
while abs(eps)>1e-4
df1=subs(df,x,x0);
dff2=subs(dff,x,x0);
if dff2==0
break
else
xx=x0-(1/dff2)*df1;
end
eps=xx-x0;x0=xx;
end
x0
min=subs(f,x,x0)
运行结果:
x0 =
1.3788
min =