fplot(@(x) x*(sin(x))^2*cos(x),[-2*pi 2*pi]);
[xMin1 fvalmin1] = fminbnd('-x*(sin(x))^2*cos(x)', -6, 6)
returns xMin1 = 1.0954
fvalmin1 = -0.3963
How is this possible, look at the plot?

3 个评论

Why do you say it's a bug?
Not where the minimum is! look at the plot
Solved, The function doesn't really do much, it give you the nearest point that's a minimum to it's starting point. In my case it woud be 0 as the starting point. Typical

请先登录,再进行评论。

 采纳的回答

Walter Roberson
Walter Roberson 2019-1-20

0 个投票

No bug. fminbnd is a local minimizer, not a global minimizer.

3 个评论

Hi Roberson,
I have a similar problem with fminbnd, see code below
a=-200; b=-979.8997; c=7.1833e+05; d=24.4232;e=-6.6083;
x1=0; x2=4.1135e-06;
f=@(x)a-(a-b)*cos(c*(x-x1)) + d*e*sin(c*(x-x1))
f = function_handle with value:
@(x)a-(a-b)*cos(c*(x-x1))+d*e*sin(c*(x-x1))
fplot(f, [x1 x2])
[xmin, min]=fminbnd(f, x1, x2)
xmin = 1.5712e-06
min = -679.5775
We could see from the plot the minimum value should be around -996 and there should be only one local minimum. But fminbnd returns -679.
Thanks a lot in advance!
Best Regards,
Zhe
Since the changes in the x-values are in the order of 1e-6, you must choose a smaller value for TolX:
a=-200; b=-979.8997; c=7.1833e+05; d=24.4232;e=-6.6083;
x1=0; x2=4.1135e-06;
f=@(x)a-(a-b)*cos(c*(x-x1)) + d*e*sin(c*(x-x1))
f = function_handle with value:
@(x)a-(a-b)*cos(c*(x-x1))+d*e*sin(c*(x-x1))
fplot(f, [x1 x2])
options = optimset('TolX',1e-8);
[xmin, min]=fminbnd(f, x1, x2, options)
xmin = 2.8422e-07
min = -996.4246
Hi Torsten, thank you very much!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Vector Fields 的更多信息

产品

版本

R2018b

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by