简体   繁体   中英

Solving a 4th order BVP using python

I am trying to solve a 4th order ODE

  • EI*(d4y/dx4) = -k*y

which is a version of an ODE for a foundation on soft soil.

My system of first-order equations is the following

  • y1' = y2
  • y2' = y3
  • y3' = y4
  • y4' = -k*y1

and the BCs

  • y3(0) = y3(L) = 0
  • y4(0) = -F/(EI)
  • y4(L) = 0

and my code

from scipy.integrate import solve_bvp
import numpy as np

F = 300 #kN
EI = 20000 #kNm2
D = 1 #m
M_E = 45000 #kN/m2
k = 1.4*M_E/D #kN/m3
L = 10 #m

x = np.linspace(0,L,101)

p = np.array([k,EI,F])

print(p)

def fun(x, y, p):
    k = p[0]
    EI = p[1]
    return np.vstack((y[1],y[2],y[3],-k*y[0]/EI))

def bc(ya, yb, p):
    F = p[2]
    EI = p[1]
    return np.array([ya[2], yb[2], ya[3]+F/EI, yb[3]])


y_a = np.zeros((4, x.size))


from scipy.integrate import solve_bvp

res_a = solve_bvp(fun, bc, x, y_a, p)

I get the following error:

#ValueError: 'bc' return is expected to have shape (7,), but actually has (4,).

Could you help me understand what I am doing wrong here and what the error means?

Thanks

So, after playing around with the code, I managed to make it work. The solution would be:

from scipy.integrate import solve_bvp
import numpy as np

F = 100 #kN
D = 1 #m
M_E = 50 #MN/m2
E_cm = 33600 #MN/m2
L = 10 #m
nodes = 40

x = np.linspace(0,L,nodes)

k = 1.4*M_E/D #kN/m3
EI = E_cm*0.25*np.pi*(D*0.5)**4 #kNm2

c =k*D/EI


def fun(x, y):
    return np.vstack((y[1],y[2],y[3],-c*y[0]))

def bc(ya, yb):
    return np.array([ya[2], yb[2], ya[3]+F/EI, yb[3]])


y_a = np.zeros((4, x.size))


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


y = res_a.sol(x)[0]*10**3
theta = res_a.sol(x)[1]*10**3
M = EI*res_a.sol(x)[2]
V = EI*res_a.sol(x)[3]



I hope this helps anyone who is struggling with implementing an ODE of orders higher than 2.

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