## MATLAB: Do different solutions arise from these seemingly identical approaches to a typing these numbers in? If I exponentiate a number as a variable, it becomes imaginary, if I type in the number directly, it stays rational

complex numbersMATLAB

I’m probably wording this poorly, but this isn’t making any sense to me.

I have a set of variables that I’ve defined as:

`K = 1.04 - rrB2 = ((C0 + C1 * ((log(dt) - C2) / (log(1/T(i)) - C3))^(1/C4)) + 1)^-1rc = ((rB2 - r)/(1 - r0))^K`

r, C0 – C4 are are all real floating constants with no imaginary portion, T is simulated temperature at step i and dt is timestep. rB2 returns a number with no imaginary constant.

For my numbers, as an example, rB2 = 1.3e-33, r = 0.79, and K = 0.25.

((1.3e-33 – 0.79)/(1-0.79)) = -3.7619, and -3.7619^0.25 = -1.3927, right?

….except when it doesn’t! Sometimes, MATLAB returns an imaginary number, 0.9848 + 0.9848i, depending on how I type the equation in. For example, here’s some command line output:

`>> ((rB2 - r)/(1-r))ans = -3.7619>> ans^Kans = 0.9848 + 0.9848i>> -3.7619^Kans = -1.3927`

what the heck?? if I state the number -3.7619 as a variable (any variable, not just ‘ans’), it comes out imaginary when exponentiated by K… but not if I type the number in by hand. Also,

`>> ((1.3e-33 - 0.79)/(1-0.79))ans = -3.7619>> ((1.3e-33 - 0.79)/(1-0.79))^0.25ans = 0.9848 + 0.9848i`

So, what is the difference between these two seemingly identical approaches of typing the numbers in?? And how do I get a script to generate a value rc that isn’t imaginary without typing it in myself every iteration of the script?

Thanks in advance.

## Best Answer