2
votes

Question: Is there symbolic ODE solver in R ? (ODE = ordinary differential equation)

I am afraid there is NO... but let me confirm from experts ...

For example, solve:

> (5x-6)^2 y' = 5(5x-6) y - 2

Here: y - unknown function, y' - its derivative

(It is easy to solve by hands: y = 1/(5(5x-6)) + C* (5x-6) , but I want to get that answer from R).


What I know:

1) There are NUMERICAL (not symbolic) solvers:

I know there are numerical ODE solvers like library(deSolve), see answer here: Can R language find a generic solution of the first order differential equation?

2) There are symbolic packages : (but they do not seem to contain ODE solvers)

There are symbolic packages in R like see Ryacas and rSymPy and also some basic symbolic calculation in base R, see: https://stats.stackexchange.com/questions/4775/symbolic-computation-in-r/4778

3) Brief overview of various differential equations solvers for R: https://cran.r-project.org/web/views/DifferentialEquations.html

However I was unable to find sumbolic ODE solvers (((

1
I'm not sure if partial derivative but try: ?D .... deriv is a generic function with a default and a formula method. It returns a call for computing the expr and its (partial) derivatives, simultaneously. It uses so-called algorithmic derivatives. If function.arg is a function, its arguments can have default values, see the fx example below.Tony Hellmuth
@TonyHellmuth thank you for your comment, however I do not quite understand it... would you be so kind to give any details ? In case my question was not clear let me phrase again: I need to get solution of ordinary differential equation...Alexander Chervov
Your best bet might be to find a good C++ library and then use rcpp to hook it to RJohn Coleman
I'm not aware of a symbolic ODE solver for R. One workaround might be to call something like Wolfram Alpha from R.Lyngbakr
you list rSymPy and since SymPy seems to include ODE solvers does that count ... ?Ben Bolker

1 Answers

2
votes

I've had a play around with Ryacas, and you can in fact get symbolic solutions to some simple ODEs without too much work. Unfortunately, YACAS fails to find a solution for your example ODE. However, depending on the ODEs you are exploring, this might still be of use. If not, I'm happy to remove this post.

As an initial simple example, let's consider the following ODE: y'' + y = 0:

  1. Load the library

        library(Ryacas);
    
  2. Since Ryacas is just an interface to YACAS, we can use YACAS' OdeSolve to solve the ODE

    yacas("OdeSolve( y\'\' + y == 0 )")
    #expression(C70 * exp(x * complex_cartesian(0, -1)) + C74 * exp(x *
    #    complex_cartesian(0, 1)))
    

    This gives the correct solution const * exp(- ix) + const * exp(+ ix).

  3. Unfortunately when using your particular example, OdeSolve fails to find a solution:

    yacas("OdeSolve( y\'\' == (5 * (5 * x - 6) * y - 2) / (5 * x - 6)^2 )")
    #expression(y(2) - (5 * ((5 * x - 6) * y(0)) - 2)/(5 * x - 6)^2)
    

    The same happens when we use the YACAS online demo.