Limits within function and optimization with accurracy
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Alan Weiss
2013-1-15
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 个评论
Giorgos Papakonstantinou
2013-1-15
1 个评论
Alan Weiss
2013-1-15
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!