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:
Weird imaginary number

Subject: Weird imaginary number

From: Ryan

Date: 21 Nov, 2008 02:46:07

Message: 1 of 3

I'm writing a code where a variable RH=-2.3927e+004 and y4=0.3500. In my code RH^y4 spits out a complex number. When I was debugging the code I tried just running the numbers w/o the variables I got the correct answer. Is there something syntax rule I'm missing or how should I code this?

Subject: Weird imaginary number

From: Matt Fig

Date: 21 Nov, 2008 03:06:02

Message: 2 of 3

I will guess you are seeing the difference between:


(-2.3927e+004)^(.35)

and

-2.3927e+004^.35

Operator precedence.

Subject: Weird imaginary number

From: Roger Stafford

Date: 21 Nov, 2008 05:35:03

Message: 3 of 3

Ryan <Galaxian8@aol.com> wrote in message <31509243.1227235597914.JavaMail.jakarta@nitrogen.mathforum.org>...
> I'm writing a code where a variable RH=-2.3927e+004 and y4=0.3500. In my code RH^y4 spits out a complex number. When I was debugging the code I tried just running the numbers w/o the variables I got the correct answer. Is there something syntax rule I'm missing or how should I code this?
--------
  You are taking a fractional power of a negative number and that will almost always lead to complex results. For example the 1/2 power of -1 is plus or minus the square root of -1, or plus or minus i, which is either of two complex values. With a power of .35 = 20/7 there are seven possible answers, all of them complex-valued.

  Mathematicians get around this ambiguity by defining

 y^x = exp(x*log(y))

where the log function has infinitely many branches in the complex plane. In Matlab the 'log' function selects the branch with imaginary part equal to pi*i for negative values of y, which generally results in a complex-valued result.

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