How do you stop getting complex result when raising negative numbers to the power of a fraction in vectors?

6 visualizaciones (últimos 30 días)
Hi there I'm trying to do a calulation which involves negative value being risen to the power of a fraction. If I just type the value into the command window it gives the correct result. -0.1544^0.8 = -0.22434... which is same result as wolfram alpha. But in the code it is stored in a vector A which then is raised to the power of 0.8.
If I just take the one element which is the same number -0.1544 of a variable and operate such as A(1).^0.8 it gives the result of -0.1815 + 0.1319i. The complex number is not what I am after and I think it happens with raising a negate number to a power in a vector/matrix. Somehow to do with the way it calcualtes it in the vector like how log(negative) = complex number or something.
I was wondering is there any way how I could change how it caluates these values so it calculates the real answer and not the complex one.
Also it even fails if I just set A = -0.1544 and then A^0.8 so its when it is stored as single variable aswell.
Thanks Jason

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de En. de 2012
^ is binding more tightly than - here, so when you request
-0.1544^0.8
what you are actually requesting is
-(0.1544^0.8)
and when you use a variable you are requesting the equivalent of
(-0.1544)^0.8
You will have to do some fancy talking to convince me that -0.22434 is a valid solution for that power.
If you want to raise -0.1544 to a power and get -0.22434... as a result, try raising it to (.9477506930285967-0.08786279824413020i)
  3 comentarios
Nachum Lerner
Nachum Lerner el 8 de Jun. de 2014
I have a similar problem, if t=-10 and y= t^(1/3) then y= -2.1544 but if t is a vector t=-10:0.01:10 then y will have complex values which shouldn't be there. Any suggestions? Thanks
John D'Errico
John D'Errico el 8 de Jun. de 2014
Nachum - you should ask this as a question, as it is a completely different issue. However, nthroot may be of some service for you.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by