Ask Your Question

Revision history [back]

Sage is giving parameters from a solved equation instead of a number

I have a second order differential equation that I'm trying to find a particular solution for. I know I can just solve it using desolve, but I'd like to write out the steps, since I have to show it to my professor.

I've written the following linear differential operator:

# `t` is defined globally using SR.var
def L(f: Expression) -> Expression:
    return f.diff(t).diff(t) - f.diff(t) - 6*f

Which is used to represent this differential equation:

f(t) = 4*t + 1
# `y` is a globally defined unknown function of `t`
deq = L(y) == f(t)

And I know the answer is _K1*e^(3*t) + _K2*e^(-2*t) - 2/3*t - 1/18. The particular solution to this equation is solved by guessing some Y(t) and solving for the coefficients using f(t), which I've tried to represent in Sage in the following way:

# `A` and `B` are globally defined variables using SR.var
Y(t) = A*t + B
solve(L(Y) == f(t), A, B)

Which ends up giving a parametric answer [A == r2, B == -1/3*(3*r2 + 2)*t - 1/6*r2 - 1/6]. I know that the actual answer is supposed to be [A == -2/3, B == -1/18]. Is there a function in Sage that I'm missing? I'm fairly new to Sage, maybe there's something I haven't read in the docs yet?