Solve for the value of two variables that returns a desired function value in the shortest amount of time.
2 views (last 30 days)
Show older comments
I want the my function to reach a certain value in the shortest amount of time, this function has two variables whose values I need to manipulate to find the most optimal value of each. How can I use MATLAB to automatically test a range of variable values to find the one that causes the function value I desire in the shortest time?
0 Comments
Answers (1)
John D'Errico
on 11 Mar 2016
Edited: John D'Errico
on 11 Mar 2016
In the shortest time?
That is impossible to answer, since not knowing your function, how can we ever know how it might be achieved. In fact, I can give an example of a function that would cause any such algorithm to essentially fail.
As for finding the optimal value of the TWO variables, this too is impossible to answer in general, since there will usually be infinitely many solutions. Which one of those infinitely many solutions is the optimal value?
You are essentially asking to solve for a point in the (x,y) plane, such that f(x,y) is equal to some given specified value z0. You can think of this as a contour plot, where only the contour for z0 is given. As such, you can visualize that there will be some curve in the (x,y) plane where ANY point along that curve satisfies the requirement.
If your goal is indeed to find ANY solution that satisfies the requirement that
z0 = f(x,y)
where f is a given function, and z0 is some specified value, then you can simply sample the function at some set of arbitrary points. As soon as you can find two points (x1,y1) and (x2,y2), such that at (x1,y1), the function returns a value less than z0, and at (x2,y2), the function is greater than z0, you have an easy solution. Use fzero to find the point along the line segment between those two points that yields exactly z0. As long as the function is continuous everywhere, then there must be SOME point on that line segment.
The result of the above scheme is guaranteed of success, and it will be fairly efficient, since fzero is pretty good. Is it truly optimal? How can I say? Again, I don't have your function to look at.
Honestly, I'm not terribly sure that this is your goal. I think perhaps you do not realize what you are asking here.
0 Comments
See Also
Categories
Find more on Nonlinear 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!