overflow in exp, python

2019-09-25 01:16发布

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 <module>
    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 <lambda>
    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.

1条回答
Anthone
2楼-- · 2019-09-25 01:49

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.

查看更多
登录 后发表回答