[Python] Sympy rsolve function returns wrong results

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following recurrence relation:

    an = 0.996 · an–1 + 0.004 · an–10 + 0.04

    with initial conditions: an = 0 for all n ≤ 9.

    Code:

    import sympy as sp

    n = sp.symbols('n')
    y = sp.Function('y')
    recurrence = sp.rsolve(
    y(n) - sp.Rational(0.996) * y(n-1) - sp.Rational(0.004) * y(n-10) - sp.Rational(0.04),
    y(n),
    {
    y(0): 0,
    y(1): 0,
    y(2): 0,
    y(3): 0,
    y(4): 0,
    y(5): 0,
    y(6): 0,
    y(7): 0,
    y(8): 0,
    y(9): 0,
    }
    )


    The wrong result I get is just a constant number. Why do I not get an expression that depends on the variable n?

    Continue reading...

Compartilhe esta Página