Search code examples
pythonsympydifferential-equations

Strange r appears in dsolve output using Sympy


I'm interested in solving the following differential equation:

eqn = 4.0*N*sqrt(N - 1)*rho(s) + (4*s**2*(N - 1) + (N - 2*s*(N - 1))**2)*Derivative(rho(s), (s, 2))

I tried using dsolve from Sympy:

dsolve(eqn,rho(s), n=5)

which gave the following output:

Eq(rho(s), -1.33333333333333*s**3*r(2.0)/N + 1.33333333333333*s**3*r(2.0) + C2*(1 - 2.0*s**2*sqrt(N - 1.0)/N) + C1*s*(1.0 - 0.666666666666667*s**2*sqrt(N - 1.0)/N) + O(s**5))

What is this strange "r(2.0)"? I tried searching, but failed to find anything useful.

Thanks for any help!


Solution

  • The presence of the Floats is a clue that something might be wrong with the input (inasmuch as it will not give the desired output). If you change your 4.0 to 4 then you will not have the recurrence functions used to solve the equation left in the solution. If you look at the finaldict value in the ode_2nd_power_series_ordinary it looks like this with your 4.0:

    {r(2): -2.0*sqrt(N - 1.0)*r(0)/N, 
     r(3): 0.666666666666667*(2*N*r(2.0) - sqrt(N - 1.0)*r(1) - 2*r(2.0))/N}
    

    instead of

    {r(2): -2*sqrt(N - 1)*r(0)/N, 
     r(3): 2*(-4*sqrt(N - 1)*r(0) - sqrt(N - 1)*r(1) + 4*sqrt(N - 1)*r(0)/N)/(3*N)}
    

    The solution using 4 instead of 4.0 has no r(2.0):

    Eq(rho(s), 
        C2*(s - 2*s**3*sqrt(N - 1)/(3*N)) + 
        C1*(1 - 8*s**3*sqrt(N - 1)/(3*N) - 
        2*s**2*sqrt(N - 1)/N + 8*s**3*sqrt(N - 1)/(3*N**2)) + O(s**5))