Solve variable coefficients second order linear ODE?

我们两清 提交于 2019-12-11 10:19:01

问题


For the variable coefficients second order linear ODE

$x''(t)+\beta_1(t)x'(t)+\beta_0 x(t)=0$

I have the numerical values (in terms of vectors) for $\beta_1(t)$ and $\beta_0(t)$, does anyone know some R package to do that? And some simple examples to illustrate would be great as well.

I googled to find 'bvpSolve' can solve constant coefficients value.


回答1:


In order to use deSolve, you have to make your second-order ODE

x''(t) + \beta_1(t) x'(t) + \beta_0 x(t)=0

into a pair of coupled first-order ODEs:

x'(t) = y(t)
y'(t) = - \beta_1(t) y(t) - \beta_0 x(t)

Then it's straightforward:

gfun <- function(t,z,params) {
      g <- with(as.list(c(z,params)),
       {
         beta0 <- sin(2*pi*t)
         beta1 <- cos(2*pi*t)
       c(x=y,
         y= -beta1*y - beta0*x))
     list(g,NULL)
}
library("deSolve")
run1 <- ode(c(x=1,y=1),times=0:40,func=gfun,parms=numeric(0))

I picked some initial conditions (x(0)=1, x'(0)=1) arbitrarily; you might also want to add parameters to the model (i.e. make parms something other than numeric(0))

PS if you're not happy doing the conversion to coupled first-order ODEs by hand, and want a package that will seamlessly handle second-order ODEs, then I don't know the answer ...



来源:https://stackoverflow.com/questions/15756058/solve-variable-coefficients-second-order-linear-ode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!