How to do Symbolic Optimization in matlab?
29 views (last 30 days)
Show older comments
Tiger Zhao
on 12 Jul 2020
Commented: Tiger Zhao
on 20 Jul 2020
For example:
syms a b c x;
y = a*x^2 + b*x + c;
gra = gradient(y,x);
solve(gra==0,x)
I got this:
ans =
-b/(2*a)
But when the question is more complex, or includes some constraints, what can i do it more easily?
Is there any "SymbolicOptimization.m" kind functions so that i can do this:
syms a b c x;
y = a*x^2 + b*x + c;
SymbolicOptimization(y,x)
And it gives the answer(I hope):
when a>0, y have globle min at x = -b/(2*a), y=...
when a<0, y have globle max at x= -b/(2*a), y=...
when a=0, y range [-inf, inf].
Yes, What i want is to let computer do the Optimization analysis based on optimization theory.
So how to do it?
Accepted Answer
Walter Roberson
on 12 Jul 2020
No, there is no function for that.
For polynomials, you can proceed by
dy = diff(y, x);
extrema = solve(dy, x);
d2y = diff(dy);
d2y_at_extrema = subs(d2y, x, extrema);
In general, d2y_at_extrema will be symbolic in your coefficients, and you would need to examine each one for the conditions under which each is positive (indicating minima) or negative (indicating maxima) or zero (indicating saddle point).
You will end up having a list of conditions under which each value might be "global" minima or maxima.
When you get beyond degree 5 (and so derivative is degree 4, exactly solvable) you will not be able to list the possibilities.
I suspect that it will be difficult to figure out the conditions for global minima or maxima for degree 4 polynomials.
Multinomials get more complicated.
Non-linear sometimes have closed-form solutions (in some sense of "closed form") but not generally.
More Answers (0)
See Also
Categories
Find more on Calculus 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!