Ask Your Question
0

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

asked 2 years ago

FlashDagger gravatar image

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 2 years ago

achrzesz gravatar image

Try this way

x = var('t')
y = function('y')(t)
y0= function('y0')(t)
desolve(diff(y,t,t) -diff(y,t)-6*y-4*t-1, y)

_K1*e^(3*t) + _K2*e^(-2*t) - 2/3*t - 1/18

A,B=var('A B')
def y0(t): return A*t+B

eq0=diff(y0(t),t,t) -diff(y0(t),t)-6*y0(t)-4*t-1; eq0

6𝐴𝑡−𝐴−6𝐵−4𝑡−1

solve([eq0.coeff(t,0),eq0.coeff(t,1)],A,B)

{A:-2/3, B:-1/18}
Preview: (hide)
link

Comments

I've since handed in the assignment, but my professor suggested the same solution.

He told me I forgot to move f(t) to the other side of the equation, much like you did. Thank you, kind stranger!

FlashDagger gravatar imageFlashDagger ( 1 year ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 944 times

Last updated: May 01 '23