简体   繁体   English

使用 scipy 的 solve_bvp 求解耦合微分方程组

[英]Solve system of coupled differential equations using scipy's solve_bvp

I want to solve a boundary value problem consisting of 7 coupled 2nd order differential equations.我想解决一个由 7 个耦合的二阶微分方程组成的边值问题。 There are 7 functions, y1(x),...y7(x) , and each of them is described by a differential equation of the form有 7 个函数y1(x),...y7(x) ,它们中的每一个都由以下形式的微分方程描述

d^2yi/dx^2 = -(1/x)*dyi/dx - Li(y1,...,y7) for 0 < a <= x <= b,

where Li is a function that gives a linear combination of y1,...,y7 .其中Li是一个函数,它给出y1,...,y7的线性组合。 We have boundary conditions for the first-order derivatives dyi/dx at x=a and for the functions yi at x=b :我们对在x=a处的一阶导数dyi/dx和在x=b处的函数yi有边界条件:

dyi/dx(a) = Ai,
yi(b) = Bi.

So we can rewrite this as a system of 14 coupled 1st order ODEs:所以我们可以将其重写为一个由 14 个耦合的一阶 ODE 组成的系统:

dyi/dx = zi,
dzi/dx = -(1/x)*zi - Li(y1,...,y7),

zi(a) = Ai,
yi(b) = Bi.

I want to solve this system of equations using the Python function scipy.integrate.solve_bvp .我想使用 Python 函数scipy.integrate.solve_bvp求解这个方程组。 However, I have trouble understanding what exactly should be the input arguments for the function as described in the documentation ( https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_bvp.html ).但是,我很难理解文档( https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_bvp.html )中描述的函数的输入参数到底应该是什么。

The first argument that this function requires is a callable fun(x,y) .这个函数需要的第一个参数是一个可调用的fun(x,y) As I understand it, the input argument y must be an array consisting of values of yi and zi , and gives as output the values of zi and dzi/dx .据我了解,输入参数y必须是由yizi的值组成的数组,并给出zidzi/dx的值作为输出。 So my function would look like this (pseudocode):所以我的函数看起来像这样(伪代码):

def fun(x,y):
    y1, z1, y2, z2, ..., y7, z7 = y
    return [z1, -(1/x)*z1 - L1(y1,...,y7),
            ...,
            z7, -(1/x)*z7 - L7(y1,...,y7)]

Is that correct?那是对的吗?

Then, the second argument for solve_bvp is a callable bc(ya,yb) , which should evaluate the residuals of the boundary conditions.然后, solve_bvp的第二个参数是一个可调用的bc(ya,yb) ,它应该评估边界条件的残差。 Here I really have trouble understanding how to define such a function.在这里,我真的很难理解如何定义这样的功能。 It is also not clear to me what exactly the arrays ya and yb are and what shape they should have?我也不清楚数组yayb到底是什么以及它们应该具有什么形状?

The third argument is x , which is the 'initial mesh' with a shape (m,) .第三个参数是x ,它是形状为(m,)的“初始网格”。 Should x consist only of the points a and b , which is where we know the boundary conditions? x是否应该仅由点ab组成,这是我们知道边界条件的地方? Or should it be something else?还是应该是别的东西?

Finally the fourth argument is y , which is the 'initial guess for the function values at the mesh nodes', and has shape (n,m) .最后第四个参数是y ,它是“网格节点处函数值的初始猜测”,形状(n,m) Its ith column corresponds with x[i] .它的第 i 列对应于x[i] I guess that the 1st row corresponds with y1 , the 2nd with z1 , the 3rd with y2 , etc. Is that right?我猜第一行对应y1 ,第二行对应z1 ,第三行对应y2 ,等等。对吗? Furthermore, which values should be put here?此外,应该把哪些值放在这里? We could put in the known boundary conditions at x=a and x=b , but we don't know how the function looks like at any other points.我们可以在x=ax=b处加入已知的边界条件,但我们不知道函数在任何其他点的样子。 Furthermore, how does this y relate to the function bc(ya,yb) ?此外,这个y与函数bc(ya,yb)有什么关系? Are the input arguments ya,yb somehow derived from this y ?输入参数ya,yb是否以某种方式从这个y派生而来?

Any help with understanding the syntax of solve_bvp and its application in this case would be greatly appreciated.任何有助于理解solve_bvp的语法及其在这种情况下的应用的帮助将不胜感激。

For the boundary condition, bc returns the residuals of the equations.对于边界条件, bc返回方程的残差。 That is, transform the equations so that the right side is zero, and then return the vector of the left sides.即对方程进行变换,使右边为零,然后返回左边的向量。 ya,yb are the state vectors at the points x=a,b . ya,yb是点x=a,b的状态向量。

For the initial state, it could be anything.对于初始状态,它可以是任何东西。 However, "anything" in most cases will lead to failure to converge due to singular Jacobian or too large mesh.然而,“任何东西”在大多数情况下都会由于奇异的雅可比或太大的网格而导致无法收敛。 What the solver does is solve a large non-linear system of equations (see collocation method).求解器所做的是求解大型非线性方程组(参见搭配方法)。 As with any such system, convergence is most assured if you start close enough to the actual solution.与任何此类系统一样,如果您开始与实际解决方案足够接近,则最能确保收敛。 So you can try for yi所以你可以试试yi

  • constant functions with value Bi值为Bi的常数函数
  • linear functions with slope Ai and value Bi at x=bx=b处具有斜率Ai和值Bi的线性函数

with the values for zi using the derivatives of these functions.使用这些函数的导数得到zi的值。 There is no guarantee that this works, especially as close to zero you have basis solutions close to the constant solution and the logarithm, the closer a is to zero, the more singular this becomes.不能保证这是有效的,特别是当接近零时,你有接近常数解和对数的基解, a越接近零,它变得越奇异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM