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

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com