Estoy empezando en el mundo del Python, interesado en aprender éste lenguaje y en lo posible retroalimentar a los demás con lo que valla aprendiendo.
Adjunto mi primer proyecto, me sale un error de: TypeError: can't convert complex to float.
Requiero que me imprima los valores de la última línea, y al revisar los valores de las ecuaciones no encuentro falla, no sé si es por notación o que hace referencia el error.
Adjunto mi primer proyecto, me sale un error de: TypeError: can't convert complex to float.
- import math as math
- from math import pi
- from math import exp
-
- #CONVERSIÓN GRADOS-RADIANES
- def radianes(theta):
- thetarad=theta*pi/180
- return thetarad
-
- def grad(alpha):
- alphagrad=alpha*180/pi
- return alphagrad
- pass
-
- #VARIABLES CONOCIDAS
- a=7
- b=9
- c=3
- d=8
- for Th2 in range(360):
- Th2rad=radianes(Th2)
-
- #CONSTANTES: K1 K2 K3
- K1=d/a
- K2=d/c
- K3=((a**2-b**2+c**2+d**2)/(2*a*c))
-
- #VARIABLES: A B C
- A=(math.cos(Th2rad)-K1-K2*math.cos(Th2rad)+K3)
- B=(-2*math.sin(Th2rad))
- C=(K1-(K2+1)*math.cos(Th2rad)+K3)
-
- #VARIABLES: THETA 4
- Th41=(2*math.atan((-B+(B**2-(4*A*C))**0.5)/2*A))
- Th42=(2*math.atan((-B-(B**2-(4*A*C))**0.5)/2*A))
-
- #VARIABLES: K4 K5
- K4=d/b
- K5=((c**2-d**2-a**2-b**2)/(2*a*b))
-
- #VARIABLES: D E F
- D=(math.cos(Th2rad)-K1+K4*math.cos(Th2rad)+K5)
- E=(-2*math.sin(Th2rad))
- F=(K1+((K4-1)*math.cos(Th2rad))+K5)
-
- #VARIABLES: THETA 3
- Th31=(2*math.atan((-E+(E**2-(4*D*F))**0.5)/(2*D)))
- Th32=(2*math.atan((-E-(E**2-(4*D*F))**0.5)/(2*D)))
-
- #ÁNGULO DE TRANSMISIÓN
- ThT1=(((Th31-Th41)**2)**0.5)
- ThT2=(((Th32-Th42)**2)**0.5)
-
- if ThT1 > (pi/2):
- ThT1=(ThT1-pi/2)
- print(ThT1)
-
- if ThT2 > (pi/2):
- ThT2=(ThT2-pi/2)
- print(ThT2)
-
- #RESULTADOS
- Resultados = [Th2,grad(Th41),grad(Th42),grad(Th31),grad(Th32),grad(ThT1),grad(ThT2)]
- print(Resultados)
Requiero que me imprima los valores de la última línea, y al revisar los valores de las ecuaciones no encuentro falla, no sé si es por notación o que hace referencia el error.