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:
need help

Subject: need help

From: trying hope

Date: 7 Jan, 2009 03:53:01

Message: 1 of 5

Hi, I'm new to matlab. I try to calculate (-4)^(1/3). I got an imaginary answer. Could anyone told me how to express (-4)^(1/3) in matlab to get a correct answer?Thanks a lot.

Subject: need help

From: Kenneth Eaton

Date: 7 Jan, 2009 03:59:02

Message: 2 of 5

"trying hope" <withhope2007@hotmail.com> wrote in message <gk18ut$k3$1@fred.mathworks.com>...
> Hi, I'm new to matlab. I try to calculate (-4)^(1/3). I got an imaginary answer. Could anyone told me how to express (-4)^(1/3) in matlab to get a correct answer?Thanks a lot.

Try using the function NTHROOT.

hth,
Ken

Subject: need help

From: trying hope

Date: 7 Jan, 2009 04:03:02

Message: 3 of 5

got it. Thanks a lot!

"Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in message <gk19a6$kr8$1@fred.mathworks.com>...
> "trying hope" <withhope2007@hotmail.com> wrote in message <gk18ut$k3$1@fred.mathworks.com>...
> > Hi, I'm new to matlab. I try to calculate (-4)^(1/3). I got an imaginary answer. Could anyone told me how to express (-4)^(1/3) in matlab to get a correct answer?Thanks a lot.
>
> Try using the function NTHROOT.
>
> hth,
> Ken

Subject: need help

From: Roger Stafford

Date: 7 Jan, 2009 10:41:02

Message: 4 of 5

"trying hope" <withhope2007@hotmail.com> wrote in message <gk18ut$k3$1@fred.mathworks.com>...
> Hi, I'm new to matlab. I try to calculate (-4)^(1/3). I got an imaginary answer. Could anyone told me how to express (-4)^(1/3) in matlab to get a correct answer?Thanks a lot.
----------
  The function f(z) = z^(1/3) on the complex plane has the property that what mathematicians call its "analytic continuation" has three branches. It cannot be defined as a continuous function over the whole plane unless it is allowed to have three possible values at each point z (except at z=0.) If you start at, say, z = 8 with f(8) = 8^(1/3) = 2, and proceed in a counterclockwise circular path around the origin, never allowing any discontinuous jumps along the way, when you return back to the point z = 8, then f(z) will of necessity have a different value there, namely -1+sqrt(3)*i. If you go around once more, it will have changed to -1-sqrt(3)*i. Finally after three trips around it will return to the original real value 2. That is the significance of the three branches. You will note that the cube of each of these three possible values gives the value 8 as it should.

  In their power operation '^' which is designed to handle complex values, Mathworks cannot know which branch a user wishes to be on and therefore can give values for only one of the branches, namely what is known as the "principal" branch, as is frequently done in mathematics. This branch gives real values for z along the positive real axis and is continuous everywhere except along the negative real axis where it has a discontinuous jump across that axis. It is along this negative real axis that you got your unexpected answer. This is called a "branch cut". If you had moved z a tiny ways below the real axis the value would have taken a discontinuous jump.

  If you read the description of the matlab 'nthroot' function, you will notice that it applies only to real numbers and therefore does not face the problem of multiple branches. It will presumably give you an error message if you pass it a complex argument.

  End of mini-lecture on analytic function theory.

Roger Stafford

Subject: need help

From: Steven Lord

Date: 7 Jan, 2009 15:13:22

Message: 5 of 5


"trying hope" <withhope2007@hotmail.com> wrote in message
news:gk18ut$k3$1@fred.mathworks.com...
> Hi, I'm new to matlab. I try to calculate (-4)^(1/3). I got an imaginary
> answer. Could anyone told me how to express (-4)^(1/3) in matlab to get a
> correct answer?Thanks a lot.

In addition to what Ken and Roger said, if you want to obtain all three
values of (-4)^(1/3), use ROOTS.

x = (-4)^(1/3) =>

x^3 = (-4) =>

x^3 + 4 = 0 =>

x = roots([1 0 0 4])
% check
difference = (x.^3) - (-4)

The elements of difference should be very small and one of the elements of x
should be the complex value you received from (-4)^(1/3) [or pretty close to
it.] The other two elements of x are the negative real value that you
expected from (-4)^(1/3) and the complex conjugate of the result you
received from (-4)^(1/3).

--
Steve Lord
slord@mathworks.com

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