I built a calculator for a bio equation, and I think I've narrowed down the source of my problem, which is a natural log I take:
goldman = ((R * T) / F) * cmath.log(float(top_row) / float(bot_row))
print("Membrane potential: " + str(goldman) + "V"
My problem is that it will only display the output in a complex form:
Membrane potential: (0.005100608207126714+0j)V
Is there any way of getting this to print as a floating number? Nothing I've tried has worked.
It should be relatively easy to see that, if a complex number z has magnitude r and argument θ, then: z=r(cosθ+isinθ) This is called the polar form of a complex number. Thus, if you want to convert from polar form to rectangular form, remember that Re(z)=rcosθ and Im(z)=rsinθ.
The form in which we usually see complex numbers in is called rectangular form: z = a + b i , where are real numbers and .
Complex numbers have a real part and an imaginary part:
>>> c = complex(1, 0)
>>> c
(1+0j)
>>> c.real
1.0
It looks like you just want the real part... so:
print("Membrane potential: " + str(goldman.real) + "V"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With