How to do Symbolic Optimization in matlab?

29 views (last 30 days)
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?
  2 Comments
Tiger Zhao
Tiger Zhao on 12 Jul 2020
Sorry, when a=0, b!=0, y range [-inf, inf].
Tiger Zhao
Tiger Zhao on 12 Jul 2020
Oh, shit, Mathematica@ can do it.

Sign in to comment.

Accepted Answer

Walter Roberson
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)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!