http://www.mathworks.com/matlabcentral/newsreader/view_thread/325173
MATLAB Central Newsreader  Re: Problems with real cubic roots / nthroot etc...
Feed for thread: Re: Problems with real cubic roots / nthroot etc...
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 13 Dec 2012 05:04:23 +0000
Re: Problems with real cubic roots / nthroot etc...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325173#893638
bartekltg
W dniu 20121212 20:24, D R G pisze:<br>
> All of these solutions appear to have a square root term sqrt(G^2o^2  Go^4)<br>
> which always turns out to be negative; trying to take the cubic root with<br>
> nthrootin matlab later on produces an error about the inputs needing to be real<br>
<br>
If root is real, partial results is complex, but root will be real,<br>
imaginary part will cancel to zero. In 'elementary' calculation you<br>
can't avoid this, however there is hope.<br>
<br>
Read whole article, especial this method:<br>
<a href="http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method">http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method</a><br>
<br>
"When a cubic equation has three real roots, the formulas expressing<br>
these roots in terms of radicals involve complex numbers. It has been<br>
proved that when none of the three real roots is rationalâ€”the casus<br>
irreducibilisâ€” one cannot express the roots in terms of real radicals.<br>
Nevertheless, purely real expressions of the solutions may be obtained<br>
using hypergeometric functions,[22] or more elementarily in terms of<br>
trigonometric functions, specifically in terms of the cosine and<br>
arccosine functions."<br>
<br>
<br>
Translate your equation to canonical form and use trigonometric method.<br>
<br>
<br>
> I am currently using graphical methods to find but it's not<br>
> very elegant.<br>
<br>
In matlab we have roots function.<br>
it's not elegant too:)<br>
<br>
bartekltg

Thu, 13 Dec 2012 18:59:08 +0000
Re: Problems with real cubic roots / nthroot etc...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325173#893674
Roger Stafford
> W dniu 20121212 20:24, D R G pisze:<br>
> > All of these solutions appear to have a square root term sqrt(G^2o^2  Go^4)<br>
> > which always turns out to be negative; trying to take the cubic root with<br>
> > nthrootin matlab later on produces an error about the inputs needing to be real<br>
         <br>
Dave, the following is a "general solution in terms of c" using matlab operations for your cubic equation 2*c^33*o*c^2+G*o=0.<br>
<br>
R = 1/16*G*o^2*(Go^2);<br>
s = 1/8*o*(o^22*G);<br>
t = 1/3*atan2(sqrt(R),s);<br>
r = (s^2R)^(1/6);<br>
c1 = o/2 + 2*r*cos(t); % These are the three real roots<br>
c2 = o/2 + 2*r*cos(t+2/3*pi);<br>
c3 = o/2 + 2*r*cos(t2/3*pi);<br>
<br>
It is assumed here that R is negative  that is, that G is less than o^2  in which case there will always be three real roots. This is the trigonometric method referred to by Bartekltg, adapted here to make use of the 'atan2' function.<br>
<br>
Of course you could also just use matlab's 'roots' function for this purpose. However the above makes it clear just what mathematical operations are performed in obtaining the roots.<br>
<br>
Roger Stafford