exp在python中,在EXP,Python中溢出

can't really figure out why this error RuntimeWarning: overflow encountered in exp is showing up. The function I'm trying to implement is:

Id = lambda t_u, yp: Is * (np.exp((Vin(t_u) - L*yp)/(n_Ut*Ut)) - 1.0)

with values:

Vin = lambda t: Vo * np.sin(2*np.pi*w*t)

L = 50e-3 # 50 mH

Vo = 5 # 5 V

w = 50 # 50 Hz

Is = 1e-9 # 1 nA

Ut = 25e-3 # 25 mV

n_Ut = 1.0

The function Id is part of a ODE that I'm trying to solve with Runge-Kutta-Method.

EDIT:

Methoden\Serien\6>python circuit.py

Traceback (most recent call last):

File "circuit.py", line 148, in

perform_experiment(exrk_o5(), "exrk_o5")

File "circuit.py", line 48, in perform_experiment

t, y = run_method(method, label)

File "circuit.py", line 69, in run_method

t, y = method.__call__(circuit_rhs, y[0, :], t_end, n_steps)

File "C:\Users\-\numerical_methodes\6\rk.py", line 49, in __call__

t[k+1],y[k+1, :] = self.step(f, y[k, :], t[k], dt)

File "C:\Users\-\numerical_methodes\6\rk.py", line 102, in step

dydt[:, i] = rhs(t + c[i] * dt, y0 + dt * np.dot(A[i, :].T, dydt.T))

File "circuit.py", line 38, in circuit_rhs

dydt= np.array ([y[1] , Id(t, y [1]) /(C*L) - y [1]/( R*C) - y [0]/( C*L)])

File "circuit.py", line 27, in

Id = lambda t_u, yp: Is * (np.exp((Vin(t_u) - L*yp)/(n_Ut*Ut)) - 1.0)

FloatingPointError: overflow encountered in exp

where y[1]=0 and y[0]=0, as first values. The rk.py file is just the implementation of the Runge-Kutta-Method.

解决方案

Vin can return a value as high as 1.0; then you subtract something, resulting in an utterly unknown quantity. You multiply that by 40, subtract 1, and raise epsilon to that power. Depending on the value of yp, there's plenty of room for overflow in this process. A sufficiently negative value for yp will cause the problem without reference to intermediate computations.

numpy.exp(n) overflows for some value in the range 700-800. This suggests that yp is perhaps <= -350.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值