Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a complex number?

Tags:

python

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.

like image 899
Sartorible Avatar asked Feb 16 '16 04:02

Sartorible


People also ask

How do you convert complex numbers from polar to Cartesian?

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θ.

How do you convert complex numbers to rectangular form?

The form in which we usually see complex numbers in is called rectangular form: z = a + b i , where are real numbers and .


1 Answers

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"
like image 180
mgilson Avatar answered Nov 14 '22 15:11

mgilson