Returning incorrect values with complex numbers in Python
<p>I'm working a physics problem with complex numbers and think I'm setting everything up correctly but am obviously not doing something right along the way. It could be that I'm either not using the right equations or that I'm unfamiliar with how Python's handling the math, and I'm pretty sure I'm using the right stuff. I've already worked a problem using the same kind of procedure and got the correct value, so substituting my new values should </p>

<p>Given <code>f = 1000, SWR = -5.9, L = 0.081</code>, I apparently should be getting <code>z = 1.4 - 0.23j</code>.</p>

<p>Here's what I'm doing:</p>

<pre><code>import numpy as np
import cmath

f = 1000     #frequency
SWR = -5.9
L = 0.081

w = 2*f*np.pi     #angular frequency
c = 343     #speed of sound in air
k = w/c     #wavenumber

BA = (SWR-1)/(SWR+1)     #given
theta = 2*k*L-np.pi     #given

z = (1+BA*np.e**(1j*theta))/(1-BA*np.e**(1j*theta))     #given
print(z)
</code></pre>

<p>This gives me <code>z = (-4.699946746470462-2.3316919882323677j)</code>, obviously not what I'm being told is the correct value.</p>

<p>I've gone over this multiple times now and can't find anything wrong. I just again worked through the problem I already got correct and made the minor substitutions to fit these given values, and I'm still getting the returned value of z. I don't want to tell my professor his "check that your code is giving the correct results" result is wrong, but...</p>

<p>Am I missing something?</p>

<p>E: Apologies for the rough display, but I'm not sure I can type in LaTeX here. The following are what I'm working with. Furthermore, the final image shows that I worked basically the same problem correctly and that I should be able to just make some substitutions to work this one. Also note that in my code, z is actually z divided by the rho<em>c</em>S quantity. I'm after that, don't need to know their values.</p>

<p><a href="https://imgur.com/a/PtRqv" rel="nofollow noreferrer">Equation for z, BA, theta, and the worked similar problem</a></p>