Я пытаюсь найти переменную B в этом длинном выражении. Это дает мне ошибку, что он не может преобразовать в float. Я не совсем уверен, что именно это означает и что мне нужно сделать, чтобы исправить это и получить значение для B. Я очень новичок в Python, поэтому любая помощь будет оценена по достоинству.
Код:
import matplotlib.pyplot as plt
import numpy as np
import math
from sympy.solvers import solve
from sympy import Symbol
W = 1*(10**(-4))
mu = 300
Cox = 6.906*(10**-6)
Leff = 1*(10**(-4))
Vg1 = 0.5
Vg2 = 1.0
Vg3 = 1.5
Vg4 = 2.0
Vth = 0.0259
tsi = 5 * (10 ** -7)
Vg = [0.5, 1, 1.5, 2]
Esi = 11.7
tox = 1.5 * (10 ** -7)
tsi = 5 * (10 ** -7)
ni = 1.5 * (10 ** 10)
q = 1.602 * (10 ** -19)
B = Symbol('B')
solve((Vg1/2*Vth) - math.log((2/tsi)*(np.sqrt((2*Esi*Vth)/(ni * q)))) -
math.log(B) + math.log(np.cos(B)) - 2*11.7*(tox)/(3.9 * tsi), B)
Ошибка:
TypeError Traceback (most recent call last)
<ipython-input-3-003cda8dedbd> in <module>()
18 B = Symbol('B')
19
---> 20 solve((Vg1/2*Vth) - math.log((2/tsi)*(math.sqrt((2*Esi*Vth)/(ni *
q)))) - math.log(B) + math.log(math.cos(B)) - 2*11.7*(tox)/(3.9 * tsi), B)
~\Anaconda3\lib\site-packages\sympy\core\expr.py in __float__(self)
237 if result.is_number and result.as_real_imag()[1]:
238 raise TypeError("can't convert complex to float")
--> 239 raise TypeError("can't convert expression to float")
240
241 def __complex__(self):
TypeError: can't convert expression to float
import sympy
вверху файла и заменитеmath.log(B)
наsympy.log(B)
, аmath.log(np.cos(B))
наsympy.log(sympy.cos(B))
. - person jdehesa   schedule 24.05.2018