symbolic cubic polynomial solver

25 views (last 30 days)
Sakai
Sakai on 15 Mar 2015
Commented: John D'Errico on 15 Mar 2015
Cubic polynomial always has a zero point on the real line, so I run something like
syms x a
solve(x^3+x^2-x+a,'real',true)
ans =
sin(atan((2*(1/27 - a^2/4)^(1/2))/a)/3) -...
1/(3*((a^2/4 - 1/27)^(1/2) - a/2)^(1/3)) + ...
sin(atan((2*(1/27 - a^2/4)^(1/2))/a)/3 - pi/3)...
- 1/(3*(a/2 - (a^2/4 - 1/27)^(1/2))^(1/3))...
- sin(atan((2*(1/27 - a^2/4)^(1/2))/a)/3)...
- sin(atan((2*(1/27 - a^2/4)^(1/2))/a)/3 - pi/3) -...
(2*3^(1/2)*cos(atan((2*(1/27 - a^2/4)...
(2*3^(1/2)*cos(atan((2*(1/27 - a^2/4)^(1/2))...
I cut the ... part b/c it's too long, but my point is that Matlab gave me 8 solutions. Can somebody tell me what is going on? Where is the fundamental theorem of algebra?

Accepted Answer

John D'Errico
John D'Errico on 15 Mar 2015
Hmm. Did you tell it what to solve for? Should MATLAB magically know that x was your unknown, and a only a symbolic constant, for which you have chosen not to supply a value?
solve(x^3+x^2-x+a,x)
This returns 3 solutions. A problem is that 1 or 3 of them MAY be real, depending on the value of a. Since you won't tell MATLAB what is a, it can't know yet which one(s) are real.
  6 Comments
Sakai
Sakai on 15 Mar 2015
Now I understand what you really mean. Thank you very much!
John D'Errico
John D'Errico on 15 Mar 2015
Good. I do admit that until I decided to do those last few things, I think there was some confusion as to why MATLAB was returning 8 solutions, or what appeared to be 8 of them.

Sign in to comment.

More Answers (1)

Andrew Newell
Andrew Newell on 15 Mar 2015
Edited: Andrew Newell on 15 Mar 2015
I ran the same code and got 3 solutions:
syms x a
xsols = solve(x^3+x^2-x+a,'real',true);
size(xsols)
ans =
3 1
I think you're interpreting those eight lines as one solution per line, but the triple dots at the end of the line mean that the solution continues on the next line. You are really just displaying one of the three solutions.
  4 Comments
Andrew Newell
Andrew Newell on 15 Mar 2015
It appears that in 2014a, the option 'real',true didn't have any effect; but in 2014b, the engine is trying to figure out what parts of the solution are real.
Consider: in complex space, for each value of a (which, as far as solve knows might be complex) you have three complex solutions. Without 'real',true, solve is returning the equations for (real(x), imag(x)) as a function of (real(a), imag(a)) - not a line, but a surface. With 'real',true, it is trying to determine where this surface intersects imag(x) = 0. That could be any number of line segments.
Sakai
Sakai on 15 Mar 2015
I see. Thank you very much!

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!