how to find two minimums within a range?
6 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Bladi Toaza
on 27 Jan 2021
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).
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!