how to find two minimums within a range?
显示 更早的评论
Hello People,
I got stuck on question regarding finding 2 minima of function. the equation is
f(x)= exp(-sqrt(x))+ 0.1*sin(3x)
In question it says using function handles, does that mean i have to define function handle specifically, and call it later or i can use anonymous function. I have written following code using anonymous function but it won't return both values together.
>>fminbnd(@(x)exp(-sqrt(x))+0.1*sin(3*x),0,2) and
>>fminbnd(@(x)exp(-sqrt(x))+0.1*sin(3*x),2,5)
Any suggestions would help. As always,thank you for your trouble and Good health to you.
回答(1 个)
Bladi Toaza
2021-1-27
0 个投票
As I understand you are looking fot the local minima of the functions. You can use the function islocalmin. This will return a logical array with values 1 (true) when it is a lcoal minima.
f= exp(-sqrt(x))+ 0.1*sin(3x)
TF = islocalmin(f)
plot(x,f,x(TF),f(TF),'r*')
This will return the local mimima of the functions (that could be 1,2 or more).
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!