Store all iterations of a symbolic variable as double, numeric, etc. while using fmincon optimization to visualize post-run
5 views (last 30 days)
Show older comments
I am using fmincon to optimize a two-reservoir system. Following the example syntax, I am using symbolic variables for reservoir storage, inflow, and releases. However, following optimization, I would like to plot and visualize the reservoir storage. I have tried cell2mat, double() and other ways of converting the symbolic variables to a format that can be used to see all iterations, but get an error each time.
What is the best way to have all iterations of each variable stored during optimization using fmincon, and what syntax should I use to convert them out of symbolic and see the values?
Thanks.
0 Comments
Answers (1)
Walter Roberson
on 14 Apr 2018
If double() fails on them, then they very likely still have symbolic variables in them, and cannot be directly plotted. To plot something that contains a symbolic variable you would need to substitute definite values for the symbolic variables. fplot() can do that for you if there is only one variable, and fsurf() can do that for 2 variables (producing a surface.)
6 Comments
Walter Roberson
on 17 Apr 2018
You could probably get all of those into one single symbolic vector, but you are still faced with some difficulties:
- What you are looking at there with all those equations is the value of those variables. There is no hidden numeric value
- The only way to plot those is to substitute specific numeric values for the symbolic variables. That would likely be a problem for you as it appears there are at least a few dozen symbolic variables involved and it is seldom practical to make a plot with more than 3 (at most 4) independent variables simultaneously.
When I look at those expressions, it looks to me as if you are building up an equation in a loop. I wonder if you need to store all of the iterations, or if you only need the final one?
It seems unlikely that you should be doing that computation inside an objective function. Instead likely you should be computing the equation once outside of fmincon and then using matlabFunction() to optimize over it. You would likely use the 'vars' parameter of matlabFunction to bundle a number of variables into a vector.
See Also
Categories
Find more on Linear Algebra 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!