Real solutions to polynomials

6 次查看(过去 30 天)
Robert Bag
Robert Bag 2021-4-24
评论: Robert Bag 2021-4-24
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?

回答(3 个)

Alan Stevens
Alan Stevens 2021-4-24
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 2021-4-24
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 2021-4-24
编辑:John D'Errico 2021-4-24
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.

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by