Maximizing using fminsearch over an interval
12 views (last 30 days)
Show older comments
I want to maximize
(((cos(p(1))*sin(p(2)))-(f1*(cos(p(1))*sin(p(2)))+f2*(sin(p(1))*sin(p(2)))+f3*cos(p(2)))*d1)^4+((sin(p(1))*sin(p(2)))-(f1*cos(p(1))*sin(p(2))+f2*sin(p(1))*sin(p(2))+f3*cos(p(2)))*d2)^4+((cos(p(2)))-(f1*cos(p(1))*sin(p(2))+f2*sin(p(1))*sin(p(2))+f3*cos(p(2)))*d3)^4)^(1/4);
for p(1) from -pi..pi and p(2) from -2pi..2pi
Is there a way to restrict the input to an interval?
TIA
Answers (2)
Walter Roberson
on 21 Oct 2013
No. If you have an interval use fminbnd() or related if you have the Optimization toolbox; if you do not have that toolbox then use fzero() on the derivative of the function if it is a function of one variable.
If you do not have the optimization toolbox and it is a function of more than one variable, you might be able to get somewhere using the Symbolic Mathematics Toolbox.
It appears to me that there are multiple identical maxima in the range you specify. Depending on the parameters I use, I find 8, or 12, or maybe an infinite number (I'm still processing that case to see if there is a subtle wave that I do not see visually.)
Alan Weiss
on 21 Oct 2013
Edited: Alan Weiss
on 21 Oct 2013
If you use the optimization decision table for your nonlinear problem with bound constraints, you see that you should use fmincon as your solver. It is easy to set a range for fmincon, just give lower and upper bounds.
Alan Weiss
MATLAB mathematical toolbox documentation
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!