Search code examples
pythonodesolver

Solve_ivp setting an array element with a sequence.The requested array has a inhomogen shape after1dimensions.Thedetected shape was(4,)+inhomogeneous


I am using solve_ivp for a system of 4 ODE equations but it gives me this error. Probably because y0 from the solve_ivp that i need are 4 term(initial values: x0,y0,w0,z0) and i enter this like an array . How can I enter these initial values in the solver? if i try to put like a list occur the same error. I write an example of my code (it is too long to write it all)

def funct(iv,t):
    a=iv[0]
    b=iv[1]
    c=iv[2]
    c=iv[3]
    # ODE
    dxdt=...
    dydt=...
    dwdt=...
    dzdt=...
    ODES=[dxdt,dydt,dwdt,dzdt]
    return ODES
x0=1
y0=2
w0=3 
z0=4 
initial_values=np.array([x0,y0,w0,z0]) #*******
t_s = np.linspace(0,100,1001)
#Integración del modelo
inputs = (D,E,F,G,H,J,K)
solut = odeint(funct, initial_values, t_s)


 

Solution

  • According to the documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html

    solut = solve_ivp(funct, t_s, initial_values)
    

    This would be the correct order.