微分方程BVP [英] differential equations BVP

查看:140
本文介绍了微分方程BVP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #包括微分方程和参数

def模型(x,dydx,p):
s = p [0]#第一个参数
a = p [1]#第二个参数

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])

#边界条件

def bc(ya,yb,yc,p):
s = p [0]
a = p [1]
I0 = 1

返回np.array(([ya [0],yb [0],yc [0],a,s]))
#x值
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初始值
y [0] = 3
y [1] = 3
y [2] = 2

I0 = 1

sol = solve_bvp(模型,bc,x,y,p = [1,1])$ ​​b $ b

我不知道如何写边界条件来求解三个微分方程



I w ant求解方程并具有 y 值和参数值

解决方案

对于其他问题,您有固定的参数和3个边界条件。这需要被编码为

 #边界条件
def bc(y0,yd ,I0):
返回np.array([y0 [0],y0 [2] -I0,yd [1]])

然后,初始 x 数组需要以边界点为边界



<前置类= lang-py prettyprint-override> x = np.linspace(0,d,9)
y = np.zeros((3,x.size))
#y初始值
y [0] = 3
y [1] = 3
y [2] = 2

,并且需要在不使用可变参数的情况下调用求解器,并通过包装器/局​​部求值将它们全部固定为常数值

  sol = solve_bvp(lambda t,y:model(t,y,[s,a]),lambda y0,yd:bc(y0,yd,I0) ,x,y)


#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

解决方案

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) 

这篇关于微分方程BVP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆