element wise matrix operation problem

69 Views Asked by At

I am doing an element wise power calculation, and at a given point, I get a complex value out of real values! I have attached a screen shot from the debugging mode in Matlab enter image description here

So, one can see that the first operation is giving a complex number, although both A(8,111) and 4/(gamma-1) where gamma=1.4 are real!

Can any one explain that? I guess for more details, the screen shot speaks for itself. Thank you in advance

1

There are 1 best solutions below

1
On BEST ANSWER

$A(8,111)$ is a negative number. $4/(\gamma - 1)$ should be the even integer $10$, but because of roundoff error its computed value is not quite equal to $10$.

> f = 4/(1.4 - 1)

f =

10.0000

> f - 10

ans =

1.7764e-15

A negative number to a non-integer power will get you a complex number.