Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problems with real cubic roots / nthroot etc...

Subject: Problems with real cubic roots / nthroot etc...

From: bartekltg

Date: 13 Dec, 2012 05:04:23

Message: 1 of 2

W dniu 2012-12-12 20:24, D R G pisze:
> All of these solutions appear to have a square root term sqrt(G^2o^2 - Go^4)
> which always turns out to be negative; trying to take the cubic root with
> nthrootin matlab later on produces an error about the inputs needing to be real

If root is real, partial results is complex, but root will be real,
imaginary part will cancel to zero. In 'elementary' calculation you
can't avoid this, however there is hope.

Read whole article, especial this method:
http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method

"When a cubic equation has three real roots, the formulas expressing
these roots in terms of radicals involve complex numbers. It has been
proved that when none of the three real roots is rational—the casus
irreducibilis— one cannot express the roots in terms of real radicals.
Nevertheless, purely real expressions of the solutions may be obtained
using hypergeometric functions,[22] or more elementarily in terms of
trigonometric functions, specifically in terms of the cosine and
arccosine functions."


Translate your equation to canonical form and use trigonometric method.


 > I am currently using graphical methods to find but it's not
 > very elegant.

In matlab we have roots function.
it's not elegant too:)

bartekltg

Subject: Problems with real cubic roots / nthroot etc...

From: Roger Stafford

Date: 13 Dec, 2012 18:59:08

Message: 2 of 2

> W dniu 2012-12-12 20:24, D R G pisze:
> > All of these solutions appear to have a square root term sqrt(G^2o^2 - Go^4)
> > which always turns out to be negative; trying to take the cubic root with
> > nthrootin matlab later on produces an error about the inputs needing to be real
- - - - - - - - - -
  Dave, the following is a "general solution in terms of c" using matlab operations for your cubic equation 2*c^3-3*o*c^2+G*o=0.

 R = 1/16*G*o^2*(G-o^2);
 s = 1/8*o*(o^2-2*G);
 t = 1/3*atan2(sqrt(-R),s);
 r = (s^2-R)^(1/6);
 c1 = o/2 + 2*r*cos(t); % These are the three real roots
 c2 = o/2 + 2*r*cos(t+2/3*pi);
 c3 = o/2 + 2*r*cos(t-2/3*pi);

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.

  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.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us