简体   繁体   中英

solve_ivp gets stuck, forever, with this problem

I'm trying to solve a system of differential equations with scipy.integrate.solve_ivp . The system depends on a real independent variable t and the dependent variables , c n (t) -s are complex in general. The catch is, the solver always gets stuck, no matter the dimension of the system (determined by n_max ). Here's the setup:

# Constants
from scipy.constants import hbar as h_
n_max = 2
t_max = 1

# The derivative function
def dcdt(t, c):
    return (-1.0j/h_)*((V_mat*np.exp(1.0j*w_mat*t)) @ c)

# Initial conditions
c_0 = np.zeros(n_max, dtype = complex)
c_0[0] = 1.0

#  Solving the deal
t = np.linspace(0, t_max, 10)
c = solve_ivp(dcdt, [0, t_max], c_0, t_eval = t)

And there it goes, doesn't ever stop running.
Here are sample matrices V_mat and w_mat :

>>> V_mat
array([[1.0000000e-09, 1.8008153e-56],
       [1.8008153e-56, 1.0000000e-09]])

>>> w_mat
array([[      0.        , -156123.07053024],
       [ 156123.07053024,       0.        ]])

As you will notice, V_mat and w_mat are 2-D square matrices of dimension n_max .

Is the problem tied to large/very small values in the matrices? Or is it something to do with complex values?

As I had already guessed, the problem is tied to large values in the differential equations I'm trying to solve, in particular, due to -1.0j/h_ in

def dcdt(t, c):
    return (-1.0j/h_)*((V_mat*np.exp(1.0j*w_mat*t)) @ c)

where h_ = 1.054e-34 is the reduced Planck's constant . Rescaling the equation and removing h_ fixes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM