简体   繁体   English

如何指定最终值(而非初始值)来求解R中的微分方程

[英]how to specify final value (rather than initial value) for solving differential equations in R

I would like to solve a differential equation in R (with deSolve?) for which I do not have the initial condition, but only the final condition of the state variable. 我想解决R中的一个微分方程(使用deSolve?),对于该方程,我没有初始条件,只有状态变量的最终条件。 How can this be done? 如何才能做到这一点?

The typical code is: ode(times, y, parameters, function ...) where y is the initial condition and function defines the differential equation. 典型的代码是:ode(times,y,parameters,function ...)其中y是初始条件,函数定义了微分方程。

Are your equations time reversible , that is, can you change your differential equations so they run backward in time? 您的方程式是时间可逆的 ,也就是说,您可以更改微分方程式以便它们在时间上向后运行吗? Most typically this will just mean reversing the sign of the gradient. 最典型的是,这仅意味着反转梯度的符号。 For example, for a simple exponential growth model with rate r (gradient of x = r*x ) then flipping the sign makes the gradient -r*x and generates exponential decay rather than exponential growth. 例如,对于速率为rx = r*x的梯度)的简单指数增长模型,然后翻转符号可得出-r*x梯度,并产生指数衰减而不是指数增长。

If so, all you have to do is use your final condition(s) as your initial condition(s), change the signs of the gradients, and you're done. 如果是这样,您所要做的就是将最终条件用作初始条件,更改渐变的符号,然后完成。

I initially misread your question as stating that you knew both the initial and final conditions. 最初我误解你的问题是,说明你知道初始和最终条件。 This type of problem is called a boundary value problem and requires a separate class of numerical algorithms from standard (more elementary) initial-value problems . 这种类型的问题称为边界值问题,并且需要与标准(更基本的) 初始值问题分开的一类数值算法。

library(sos)
findFn("{boundary value problem}")

tells us that there are several R packages on CRAN ( bvpSolve looks the most promising) for solving these kinds of problems. 告诉我们,CRAN上有几个R程序包( bvpSolve看起来最有前途)来解决这类问题。

Given a differential equation 给定一个微分方程

y'(t)=F(t,y(t))

over the interval [t0,tf] where y(tf)=yf is given as initial condition, one can transform this into the standard form by considering 在给定y(tf)=yf作为初始条件的间隔[t0,tf]上,可以通过考虑以下因素将其转换为标准形式

x(s) = y(tf - s)  
==>  x'(s) = - y'(tf-s) = - F( tf-s, y(tf-s) )
     x'(s) = - F( tf-s, x(s) )

now with 现在有了

x(0) = x0 = yf.

This should be easy to code using wrapper functions and in the end some list reversal to get from x to y . 使用包装器函数应该很容易编写代码,最后将一些列表反转以从x变为y


Some ODE solvers also allow negative step sizes, so that one can simply give the times for the construction of y in the descending order tf to t0 without using some intermediary x . 一些ODE求解器还允许使用负步长,因此可以简单地将y的构建时间从tf降到t0而无需使用任何中间x

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

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