MATLAB Answers

Symbolic Math Toolbox for solving algebraic equations

15 views (last 30 days)
Dear all,
here is a few my questions with regard to algebraic equations:
  1. Imagine you need to solve quadratic equation. There is following wonderful method in the Command Line:
>> syms a b c x
>> QuadraticEquation=a*x^2+b*x+c;
>> Root2=solve(QuadraticEquation)
We receive the answer what is the famous school formulas
Root2 =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
Indeed, try this
>> pretty(Root2(1))
b + sqrt(b - 4 a c)
- -------------------- %Geat!
2 a
2. Now, try to apply the same to Qubic Equation:
>> syms a b c d
>> QubicEquation=a*x^3+b*x^2+c*x+d;
>> Root3=solve(QubicEquation)
We've got
Root3 = root(a*z^3 + b*z^2 + c*z + d, z, 1)
root(a*z^3 + b*z^2 + c*z + d, z, 2)
root(a*z^3 + b*z^2 + c*z + d, z, 3)
Question No.1: What does the root(a*z^3 + b*z^2 + c*z + d, z, 1) mean? See also q.3.
Question No. 2. I did the same in the MATLAB 6.5. I've got the really wonderful answer, the Cardano formula! Why have you changed the MapleCernel to silly MuPAD?
Question No. 3: do the same for the equation with numeric coefficients,
>> r=solve(x^3+2*x^2-2*x+1)
root(z^3 + 2*z^2 - 2*z + 1, z, 1)
root(z^3 + 2*z^2 - 2*z + 1, z, 2)
root(z^3 + 2*z^2 - 2*z + 1, z, 3)
What, again, does the root(x^3 + 2*x^2 - 2*x + 1, x, 1) mean? Why cannot we use the command solve for polynomials in symbolic form like in was in MATLAB v.6.5????
My impression is that the version 6.5 was much more pleasant than recent ones.
Looking for for explanations!

Accepted Answer

Star Strider
Star Strider on 28 Feb 2020
The earlier Symbolic Math Toolbox versions used Maple as the engine, those after R2010a (if I remember correctl;y) use MuPAD.
Answer No 3:
use vpasolve instread of solve to get numeric results:
syms x
r = vpasolve(x^3+2*x^2-2*x+1)
r =
0.41558860360416845206501320695978 + 0.42484829851802604833430240038289i
0.41558860360416845206501320695978 - 0.42484829851802604833430240038289i
Star Strider
Star Strider on 29 Feb 2020
It makes sense only to the Symbolic Math Toolbox. The rest of use have to use vpasolve to make sense of it. (That is what I though I wrote.)

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 29 Feb 2020
Question 1:
Depending which MATLAB release you are using, you might see RootOf() or root() expressions showing up for solve(). The two are nearly the same, with root() being newer and having an little difference in calling sequence.
In both cases, there is the function name, then an expression usually involving a variable named z, then the second parameter is a variable name. When there is a third parameter it is typically a positive integer, but there are some cases that an expression can show up.
The meaning involved is that the placeholder stands in for the set of values of the variable in the second parameter, such that the expression comes out as exactly 0: the roots of the expression. If the third parameter is a positive integer, then the entire set of potential roots is enumerated according to some undocumented internal scheme, and the integer identifies which one of them is to be chosen.
These constructs are necessary to stand in for roots of a polynomial of degree 5 or higher since there is no closed form algebraic solution for those, but it is still common to want to reason about what you could do with the values if you could get them. And saying that closed form solutions do not exist does not mean that you cannot find good numeric approximations if the expression is a polynomial and the coefficients are all numeric.
Now, while there are closed form solutions for degree 3 and 4, a lot of the time substituting the expressions just get in the way of further work with the root: the closed form for degree 4 is quite long and pretty much unreadable. A lot of the time humans can make a lot more sense of what is going on in an expression by just knowing that at that point you would put in the root of a cubic or quartic without expanding out to the precise value. This gets very common in solving systems of simultaneous polynomials: the information about which systems is having which root tsjen becomes much clearer than thousands and thousands of symbols that express the exact answer.
Because of this, the MuPad kernel has a design decision that roots of a cubic or quartic are seldom to be expressed explicitly unless the user asks for that. You can ask for expansion when you use solve() by passing in the option 'MaxDegree' and a small integer; roots up to that degree are to be given in full when possible.
Question 2:
Maple was replaced by MuPad as an economic decision. Maple is owned by Maplesoft (though at the time it was possibly still officially Waterloo Maple, a subdivision of Maplesoft), which required that every license be paid for. There are often complications when you rely on an outside vendor that you are paying license fees to, and at some point, Mathworks found it easier to buy MuPad intellectual property.
No-one has ever spoken to me about any tensions between Mathworks and Maplesoft, but as someone who has actively used Maple for decades, I can say that historically it can be difficult to get Maplesoft to fix problems that do not happen to align with their current market strategy. It isn't that Maplesoft is indifferent, just that they are perpetually short on resources and bugs can get placed into the ever-expanding To Do list for a few decades. Maplesoft has some brilliant mathematicians, but it can be difficult to get their attention...and when you do get it, they will probably want to develop new techniques that solve for an entire class of problems instead of just fixing the immediate problem in front of them.
Question 3: As discussed in Question 1: use 'MaxDegree', 3 if you need the complete formula.
  1 Comment
Walter Roberson
Walter Roberson on 5 Mar 2020
The next release of Maple will contain fixes for 5 of the bugs I pointed out to Maplesoft. However they were all easy fixes, and some of the more difficult bugs that I have pointed out to them have been active for over a decade.
When a moderately large company such as Mathworks needs bug fixes from another company, sometimes those kinds of prioritization decisions from the other company can get frustrating. It does not mean that Maplesoft is a bad company, or that Mathworks is being too demanding, just that different companies will typically have different priorities so bringing technology in-house can make sense.

Sign in to comment.

Yevgeny Gayev
Yevgeny Gayev on 5 Mar 2020
Dear sirs,
sincere gratitude to all who answered my questions!
Yes, I see now that version 2019 need some other means that 6.5. I tested your suggestions, and there are two methods so (for the given example):
>> syms x
>> P8=2*x^8 - 3*x^7 + x^6 - x^5 + x^4 + 2*x^2 - 1 %Polynomial as symbolic data
>> ROOTS1=vpasolve(P8)
We got the same result. Great!
3. to the qubic equation in the general symbolic form:
>> syms a b c d
>> P=a*x^3+b*x^2+c*x+d
>> ROOTS=solve(P, 'MaxDegree', 3 )
And we got the famous Cardano Formula!
OK, it works up to 4th polynomial degree! But not for elder, of course.
Many thans again!

Community Treasure Hunt

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

Start Hunting!