Unable to compute roots for polynomial equation

1 view (last 30 days)
This code creates an "n"th degree polynomial equation for an "n" degree pendulum and I'm unable to complete the last step which is to solve the polynomial roots. As a check, I'm comparing it to the attached example (see below code). I need to keep it generic (not specific to n=3).
The roots come up as long strings of equations with a mysterious "i" term. (See outputs below). How do I fix this?
n=3
syms m g l x w0
g=1;
l=1;
m=1;
w0=sqrt(g/l);
T=zeros(n);
for i=1:n;
T(i,:)=n+1-i;
T(:,i)=n+1-i;
end
T=T;
V=eye(n);
for i=1:n;
V(i,i)=n+1-i;
end
V=V;
A=(eye(n)*(-w0^2)+ ones(n)*(x*w0^2)); %Set Up for w^2*T-V
A=A.*T ; %A=[w^2*T-V]/[ml^2]
B=det(A) ;
C=B/w0^(2*n) ; %EQN 10.122 IN ATTACHED EXAMPLE
D=coeffs(C)
D=fliplr(D)
roots(D) ; %THESE SHOULD MATCH THE COEFFICIENTS IN EQN 10.123 IN ATTACHED IMAGE
The outputs are as follows. Everything looks great until the very last step- finding the roots.
C =
x^3 - 9*x^2 + 18*x - 6
D =
[ -6, 18, -9, 1] [ 1, -9, 18,-6]
ans =
3/(3 + 18^(1/2)*1i)^(1/3) + (3 + 18^(1/2)*1i)^(1/3) + 3
3 - (3 + 18^(1/2)*1i)^(1/3)/2 - (3^(1/2)*(3/(3 + 18^(1/2)*1i)^(1/3) - (3 + 18^(1/2)*1i)^(1/3))*1i)/2 - 3/(2*(3 + 18^(1/2)*1i)^(1/3))
3 - (3 + 18^(1/2)*1i)^(1/3)/2 + (3^(1/2)*(3/(3 + 18^(1/2)*1i)^(1/3) - (3 + 18^(1/2)*1i)^(1/3))*1i)/2 - 3/(2*(3 + 18^(1/2)*1i)^(1/3))

Accepted Answer

Torsten
Torsten on 20 Nov 2015
Use
r=roots(D);
disp(eval(r));
Best wishes
Torsten.
  1 Comment
Stephen Figueira
Stephen Figueira on 20 Nov 2015
This seems to partially fix the problem, except the output is not sorted correctly (it's easy to discern when n=3, but when n=50+ it becomes difficult). I've tried sort commands but the non-real terms throw it off.
D =
[ 1, -9, 18, -6]
6.2899 - 0.0000i
0.4158 - 0.0000i
2.2943 + 0.0000i

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!