Unable to compute roots for polynomial equation
1 view (last 30 days)
Show older comments
Stephen Figueira
on 20 Nov 2015
Commented: Stephen Figueira
on 20 Nov 2015
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))
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!