/RationalRiccatiSolver

An ODE solver which gives all rational solutions to Riccati Equations

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

RationalRiccatiSolver

An ODE solver which uses SymPy to give all rational solutions to Riccati Equations.

Examples

These are results on SymPy 1.7.1

In [1]: from sympy.riccati import *
   ...: f = Function('f')
   ...: x = Symbol('x')

In [2]: eq = f(x).diff(x) + f(x)**2 - (4*x**6 - 8*x**5 + 12*x**4 + 4*x**3 +  7*x**2 - 20*x + 4)/(4*x**4)

In [3]: eq
Out[3]: 
                      6      5       4      3      2
 2      d          4x  - 8x  + 12x  + 4x  + 7x  - 20x + 4
f (x) + ──(f(x)) - ────────────────────────────────────────────
        dx                                4
                                       4x

In [4]: sols = find_riccati_sol(eq)

In [5]: sols[0]
Out[5]: 
     2x          3    1
x + ────── - 1 - ─── + ──
     2           2x    2
    x  - 1             x

In [6]: checkodesol(eq, sols) # Verify if the solution is correct
Out[6]: [(True, 0)]

In [7]: eq = f(x).diff(x) + f(x)**2 - (2*x + 1/x)*f(x) + x**2

In [8]: eq
Out[8]: 
 212      d
x  -2x + ─⎟⋅f(x) + f (x) + ──(f(x))
     ⎝      xdx

In [9]: sols = list(map(lambda x: x.simplify(), find_riccati_sol(eq))) # Simplify all solutions

In [10]: sols
Out[10]: 
⎡         ⎛      2    ⎞  ⎤
⎢    2  x⋅⎝C+ x  + 2⎠   ⎥
⎢x + ─, ───────────────, x⎥
⎢    x            2       ⎥
⎣           C+ xIn [11]: checkodesol(eq, sols)
Out[11]: [(True, 0), (True, 0), (True, 0)]