Real solutions to polynomials

2 views (last 30 days)
Robert Bag
Robert Bag on 24 Apr 2021
Commented: Robert Bag on 24 Apr 2021
When I do this code:
%Find all real solutions of the equations
syms x
A = x^5 - 12*x^4 + 55*x^3 - 120*x^2 + 124*x == 48;
a = solve(A,x,'Real',true)
B = x^6 - x^4/5 + 14*x^2 - 2*x - 10 == 0;
b = solve(B,x,'Real',true)
C = x^5 - 4*x^3 + 4*x^2 - (4*x)/3 - 10/3 == 0;
c = solve(C,x,'Real',true)
D = x^5 - 13*x^4 + 64*x^3 - 152*x^2 + 176*x == 80;
d = solve(D,x,'Real',true)
I get:
>> Matlab412
a =
1
2
2
3
4
b =
root(z^6 - z^4/5 + 14*z^2 - 2*z - 10, z, 1)
root(z^6 - z^4/5 + 14*z^2 - 2*z - 10, z, 2)
c =
root(z^5 - 4*z^3 + 4*z^2 - (4*z)/3 - 10/3, z, 1)
root(z^5 - 4*z^3 + 4*z^2 - (4*z)/3 - 10/3, z, 4)
root(z^5 - 4*z^3 + 4*z^2 - (4*z)/3 - 10/3, z, 5)
d =
2
2
2
2
5
In other words; I just get an expression for the real roots for b) and c).
Does anyone have a clue why?

Answers (3)

Alan Stevens
Alan Stevens on 24 Apr 2021
Try
B = x^6 - x^4/5 + 14*x^2 - 2*x - 10 == 0;
b = vpasolve(B,x)
C = x^5 - 4*x^3 + 4*x^2 - (4*x)/3 - 10/3 == 0;
c = vpasolve(C,x)
then delete the complex values.

David Hill
David Hill on 24 Apr 2021
Why not just use roots()?
a=roots([5 -12 55 -120 124 -48]);
r=[];
for k=1:length(a)
if isreal(a(k))
r=[r,a(k)];
end
end

John D'Errico
John D'Errico on 24 Apr 2021
Edited: John D'Errico on 24 Apr 2021
When you use solve, remember that first of all, it will be impossible to find algebraic solutions to a general polynomial of degree 5 or higher. This was proved a zillion years ago. Read about Abel-Ruffini. So all that solve can do in some cases is to use a numerical solver.
This one worked, because the polynomial is in fact a really easy one to solve:
syms x
A = x^5 - 12*x^4 + 55*x^3 - 120*x^2 + 124*x == 48;
a = solve(A,x,'Real',true)
a = 
But this one is more difficult:
B = x^6 - x^4/5 + 14*x^2 - 2*x - 10 == 0;
b = solve(B,x,'Real',true)
b = 
So MATLAB gets hung up. It returns a result that says, well, I know the result ins in there somewhere, but I could not find it.
We can force MATLAB to turn that into numerical values using either double or vpa.
format long g
double(b)
ans = 2×1
-0.770857012663665 0.902280599422831
vpa(b)
ans = 
Which one you use depends on whether you want a double as a result, or a symbolic floating point number.

Community Treasure Hunt

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

Start Hunting!