我在试着解那个长表达式中的变量B。它给了我一个错误,它不能转换成浮点数。我真的不知道这到底意味着什么,我需要做什么,以修复这一点,并获得一个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
按照@jdehesa的建议,使用sympy表达式:
您试图求解的表达式是非线性的,因此您应该尝试用
nsolve
进行数值求解。你知道吗注意:第二个参数是猜测结果应该接近什么。你知道吗
用
1
我得到一个复杂的结果:相关问题 更多 >
编程相关推荐