程序;
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
程序;
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 =