MATLAB: How to solve algebraic equations in Matlab 2018a?

algebraic equationcharacter vectorsMATLABmatlab 2018asolve

Hello, I was trying to solve a algebraic equation, e.g.:
syms a b c d
[c,d]=solve(2*a-b,2*b-a+3,'a','b')
On Matlab 2017b, I can get the final results with the alert: Do not specify equations and variables as character vectors. Instead, create symbolic variables with syms.
But on Matlab 2018a, only error returns: 'a' is not a recognized parameter. For a list of valid name-value pair arguments, see the documentation for this function.
So are there some updates or changes between 2017b and 2018a?
And how can I solve algebraic equations correctly in Matlab 2018a?
Thanks!

Best Answer

In R2018a, they finally stopped letting you just provide a string input. It has been something they have been threatening for several years now. The time is now up.
However, you can just do this:
syms x
xroots = solve(3*x^5+4*x^4+7*x^3+2*x^2+9*x+12)
xroots =
root(z^5 + (4*z^4)/3 + (7*z^3)/3 + (2*z^2)/3 + 3*z + 4, z, 1)
root(z^5 + (4*z^4)/3 + (7*z^3)/3 + (2*z^2)/3 + 3*z + 4, z, 2)
root(z^5 + (4*z^4)/3 + (7*z^3)/3 + (2*z^2)/3 + 3*z + 4, z, 3)
root(z^5 + (4*z^4)/3 + (7*z^3)/3 + (2*z^2)/3 + 3*z + 4, z, 4)
root(z^5 + (4*z^4)/3 + (7*z^3)/3 + (2*z^2)/3 + 3*z + 4, z, 5)
Then resolve that mess into numbers using vpa:
vpa(xroots)
ans =
-0.95832248349981782331007510989358
- 0.86122033780576856901169130559204 - 1.4377338954885689163709476213772i
- 0.86122033780576856901169130559204 + 1.4377338954885689163709476213772i
0.67371491288901081400006219387216 - 1.0159473094101229496455473520944i
0.67371491288901081400006219387216 + 1.0159473094101229496455473520944i
Or, you could have just used vpasolve directly.
vpasolve(3*x^5+4*x^4+7*x^3+2*x^2+9*x+12)
ans =
-0.95832248349981782331007510989358
- 0.86122033780576856901169130559204 + 1.4377338954885689163709476213772i
- 0.86122033780576856901169130559204 - 1.4377338954885689163709476213772i
0.67371491288901081400006219387216 - 1.0159473094101229496455473520944i
0.67371491288901081400006219387216 + 1.0159473094101229496455473520944i
Finally, if you absolutely insist on providing it as a string? Use str2sym.
vpasolve(str2sym('3*x^5+4*x^4+7*x^3+2*x^2+9*x+12'))
ans =
-0.95832248349981782331007510989358
- 0.86122033780576856901169130559204 + 1.4377338954885689163709476213772i
- 0.86122033780576856901169130559204 - 1.4377338954885689163709476213772i
0.67371491288901081400006219387216 - 1.0159473094101229496455473520944i
0.67371491288901081400006219387216 + 1.0159473094101229496455473520944i
Related Question