简体   繁体   中英

Can't start scipy's solve_bvp

I have a system of 8 differential equations with 8 boundary conditions which I'm trying to solve using scipy's solve_bvp. Bellow you can find the code I'm using

import numpy as np
from scipy.integrate import solve_bvp

def fun(x, y):

    x_dot = y[2]
    y_dot = y[1]
    vx_dot = 53441.25/(4106.89-15.23*x)*(-y[6]/np.sqrt(y[6]**2+y[7]**2))
    vy_dot = 53441.25/(4106.89-15.23*x)*(-y[7]/np.sqrt(y[6]**2+y[7]**2))-3.986e14/(y[1]+6371.0e3)**2

    lambda1_dot = 0
    lambda2_dot = 0
    lambda3_dot = -y[4]
    lambda4_dot = -y[5]

    return np.vstack((x_dot, y_dot, vx_dot, vy_dot, lambda1_dot, lambda2_dot, lambda3_dot, lambda4_dot))

def bc(ya, yb):
    return np.array([ya[0]-113021.9, yb[1]-500e3, yb[2]-7616.5, yb[3], yb[4], ya[5]-lambda2_0, ya[6]-lambda3_0, ya[7]-lambda4_0])

lambda1_0 = 0.0
lambda2_0 = 0.1
lambda3_0 = 0.1
lambda4_0 = 0.1

tf = 300

x = np.linspace(0, tf, tf*2)
y = np.zeros((8, x.size))

y[0] = 113021.9
y[1] = np.linspace(127734.0, 500.0e3, tf*2)
y[2] = np.linspace(1854.2, 7616.5, tf*2)
y[3] = np.linspace(1479.1, 0, tf*2)
y[4] = lambda1_0
y[5] = lambda2_0
y[6] = lambda3_0
y[7] = lambda4_0

res_a = solve_bvp(fun, bc, x, y)

However it looks like there's something wrong with it, since I'm getting the following error message: ValueError: all the input array dimensions except for the concatenation axis must match exactly

How can this be fixed?

You need to account for the fact that

res_a = solve_bvp(fun, bc, x, y)

runs the full array y through the function fun , thus each state variable contains an np.array for simultaneous multi-point evaluation. The return value has to be compatible with this task, the easiest way to achieve that, apart from initializing a y_dot = np.zeros_like(y) , is to set the constant return values via

lambda1_dot = 0*y[4]
lambda2_dot = 0*y[5]

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