Limits within function and optimization with accurracy
4 views (last 30 days)
Show older comments
I have the following function:
function [T, P1, P2]=myfun(x, a, b, c, d, e)
P1=(2*c*a*x(2)^3*(e - x(1))^2)/(3*e*d*b*x(1));
P2=(2*(x(1)*x(2) + e*(d/2 - x(2))))/(e*d);
T=P1+P2;
end
which has a meaning for certain conditions:
namely for all x(1)<D and for all x(2)<L/2
First of all I would like to include this limits in the function. More specifically if both conditions are not met then the calculation of each of the output does not have a meaning. How am I going to implement it?
Second I would like to optimize it for the parameter x. Specifically, I would like to find the minimum of each of the outputs within the limits that I specified above, but with a resolution of the order 10^-6. Therefore, the optimization function will search for all the x with an accuracy of 10^-6 within the range. I am aware of the optimization and global optimization toolbox but I am trying to figure out which is the specific setting that will perform such an action.
0 Comments
Answers (2)
Alan Weiss
on 15 Jan 2013
This type of constraint is called a bound. Take a look at the documentation for bounds. You might want to look at this section, too.
As far as the accuracy of your result, take a look at tolerances and stopping criteria. Follow carefully the recommendation that you not set the tolerances too small.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
0 Comments
Giorgos Papakonstantinou
on 15 Jan 2013
1 Comment
Alan Weiss
on 15 Jan 2013
I guess I don't really understand what you want. Allow me to guess, but realize that I might be off base.
Firstly, simulannealbnd is the slowest, least robust solver in the Optimization Toolbox or Global Optimization Toolbox. You would do yourself a favor not to use it unless the other solvers do not work for you. However, I realize that you might not be really trying to optimize something, but might be investigating simulated annealing, so my comment might be irrelevant.
Secondly, if you use the Optimization Decision Table or the Global Optimization Decision Table you will find that fmincon is the preferred solver for constrained optimization with a smooth objective function. I guarantee that you will get answers that are much more reliable and obtain them much faster than simulannealbnd.
Optimization Toolbox solvers attempt to save you computational effort by evaluating the objective function on very few points. But, if your objective function is quick to evaluate, and you write it in a vectorized fashion, then there is nothing wrong with putting down a big grid and evaluating the function on the grid. Look at this example for both grid generation and vectorized computation.
In other words, if you want to set the step size yourself for a solver, well, the solver generally won't let you, because it has an algorithm that is trying to minimize function evaluations, not stick to a grid that you want.
If you are really set on a grid sort of search, and don't want to compute the full grid as above, then use patternsearch. You should almost always use patternsearch anyway instead of simulannealbnd. Set appropriate bounds and mesh tolerance and initial point, and set the ScaleMesh option to 'off' using psoptimset. You might need to use many different start points to find a global optimum.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Categories
Find more on Surrogate Optimization 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!