请教符号计算及fminbnd求极值的局限性。
Show older comments
目标:求y=sin(x)^2*exp(-0.1*x)-0.5*sin(x)*(x+0.1)在-10到10区间上的极值。
(1)利用符号计算,即导数为零法
代码
syms x
y=sin(x)^2*exp(-0.1*x)-0.5*sin(x)*(x+0.1);
yd=diff(y,x);
xs0=solve(yd,x)
yd_xs0=vpa(subs(yd,x,xs0),6)
y_xs0=vpa(subs(y,x,xs0),6)
结果
(极值点)xs0 =
0.050838341410271656880659496266968
yd_xs0 =
2.29589e-41
(导数为0时的函数值)y_xs0 =
-0.00126332
(2)fminbnd求极小值
代码
x1=-10;x2=10;
[xn0,fval,exitflag,output]=fminbnd(yx,x1,x2)
结果
xn0 =
2.5148
fval =
-0.4993
exitflag =
1
output =
iterations: 13
funcCount: 14
algorithm: 'golden section search, parabolic interpolation'
message: [1x111 char]搜索区间
(3)绘图y(x)图像,重设(收窄)fminbnd搜索区间

x11=6;x2=10;
[xn00,fval,exitflag,output]=fminbnd(yx,x11,x2)
得出:xn00 =
8.0236
fval =
-3.5680
exitflag =
1
output =
iterations: 9
funcCount: 10
algorithm: 'golden section search, parabolic interpolation'
message: [1x111 char]
求出真正的最小极值点
疑问:(1)从图看目标函数有不止一个导数为0的点,为什么用符号法solve指令只找到一个导数为0的点,符号计算不是绝对精准的吗?
(2)为什么区间收窄了,fminbnd反而找到了同样存在于此前大区间的极值点?感觉这与数学直觉不符,这是由fminbnd的算法决定的吗?
望大家指点一二^_^
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!