scipy – Python Solve_ivp solver Error: ‘Required step size is less than spacing between numbers.’


When I used Python solve_ivp for this simple problem, it cannot converge and shown’Required step size is less than spacing between numbers.’ So I wonder what’s wrong with my code?

import numpy as np
import math as m
from scipy.integrate import solve_ivp
from matplotlib import pyplot as plt

def func(t,y):
    N=nz-2

    u=y
    b=y

    f1=np.zeros(N)
    f2=np.zeros(N)

    for i in range(N):
        f1(i)=b(i+1)+(u(i+2)-2*u(i+1)+u(i))/dz/dz
        f2(i)=u(i+1)+(b(i+2)-2*b(i+1)+b(i))/dz/dz

 #Boundary condition   

    u(0)=0
    b(0)=1

    u(nz-1)=0
    b(nz-1)=0

    return np.append(f1,f2)



dz=0.1
nz=1000
N=nz-2
T=120
u0=np.zeros(N)
b0=np.zeros(N)
for n in range(N):
    u0(n)=n/N
    b0(n)=n/N

IC=np.append(u0,b0)

YS=solve_ivp(func, (0,T), IC, method='BDF')