问题
#including the differential equations and parameters
def model(x,dydx,p):
s=p[0] #first parameter
a=p[1] #second parameter
dydx[0] = -2*(s+a)*y[0]+2*s*y[1]+s/2*y[2]
dydx[1] = +2*(s+a)*y[1]-2*s*y[0]-s/2*y[2]
dydx[2] = -(s+a)*y[2]
return np.vstack(dydx[0],dydx[1],dydx[2])
# boundary conditions
def bc(ya, yb,yc, p):
s=p[0]
a=p[1]
I0=1
return np.array(([ya[0], yb[0],yc[0],a,s]))
#x values
x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.zeros((3, x.size))
#p= np.zeros((3, d.size))
#y initial values
y[0]=3
y[1]=3
y[2]=2
I0 = 1
sol = solve_bvp(model, bc,x,y, p=[1,1])
I do not know how can I write the boundary conditions to solve the three differential equations
I want to solve the equations and have the y
values and parameters values
回答1:
Per the other question you have fixed parameters and 3 boundary conditions. This needs to be encoded as
# boundary conditions
def bc(y0, yd, I0):
return np.array([y0[0], y0[2]-I0, yd[1]])
Then the initial x
array needs to be bounded by the boundary points
x = np.linspace(0,d,9)
y = np.zeros((3, x.size))
#y initial values
y[0]=3
y[1]=3
y[2]=2
and the solver needs to be called without variable parameters, fixing them all to their constant values via wrappers/partial evaluation
sol = solve_bvp(lambda t,y:model(t,y,[s,a]), lambda y0,yd: bc(y0,yd,I0), x,y)
来源:https://stackoverflow.com/questions/60697878/differential-equations-bvp