Processing math: 100%
Ask Your Question
0

Remove integrals from ODE solved by desolve

asked 0 years ago

I have been working on solving some second order ODE's with desolve. When trying to solve this one with heaviside functions it always returns an answer with integrals. I am trying to have an answer that does not have integrals. Here is the code I am running:

t = var('t')
y = function('y')(t)

equation = diff(y, t, 2) + 5*diff(y, t) + 6*y == t*heaviside(t-3)
solution = desolve(equation, y, ics=[0, 2, 0])
show(solution)
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 0 years ago

Emmanuel Charpentier gravatar image

The solution you get does not evaluate the integrals, which are held expressins. The simplest way to force their evaluation is :

sage: solution.unhold()
Warning: piecewise indefinite integration does not return a continuous antiderivative
Warning: piecewise indefinite integration does not return a continuous antiderivative
1/36*(9*(2*t*e^(2*t) - 5*e^6 - e^(2*t))*e^t*heaviside(t - 3) - 4*(3*t*e^(3*t) - 8*e^9 - e^(3*t))*heaviside(t - 3))*e^(-3*t) + 6*e^(-2*t) - 4*e^(-3*t)

136(9(2te(2t)5e6e(2t))etH(t3)4(3te(3t)8e9e(3t))H(t3))e(3t)+6e(2t)4e(3t)

Thi works if and only if Sage is able to get a closed form of your integrals ; otherwise, it will return the held form...

Another way to force these evaluations is to evaluate the string representation of your representation :

sage: eval(preparse(repr(solution)))
Warning: piecewise indefinite integration does not return a continuous antiderivative
Warning: piecewise indefinite integration does not return a continuous antiderivative
1/36*(9*(2*t*e^(2*t) - 5*e^6 - e^(2*t))*e^t*heaviside(t - 3) - 4*(3*t*e^(3*t) - 8*e^9 - e^(3*t))*heaviside(t - 3))*e^(-3*t) + 6*e^(-2*t) - 4*e^(-3*t)

136(9(2te(2t)5e6e(2t))etH(t3)4(3te(3t)8e9e(3t))H(t3))e(3t)+6e(2t)4e(3t)

In that specific case, you may also convert it to sympy, where the doit() method allows for such a re-evaluation :

sage: solution._sympy_().doit()._sage_()
1/36*(9*(2*t*e^(2*t) - 5*e^6 - e^(2*t))*e^t*heaviside(t - 3) - 4*(3*t*e^(3*t) - 8*e^9 - e^(3*t))*heaviside(t - 3))*e^(-3*t) + 6*e^(-2*t) - 4*e^(-3*t)

136(9(2te(2t)5e6e(2t))etH(t3)4(3te(3t)8e9e(3t))H(t3))e(3t)+6e(2t)4e(3t)

BTW :

sage: import sympy
sage: sympy.dsolve(equation._sympy_())._sage_()
y(t) == -1/4*(5*e^6*heaviside(t - 3) - 4*C1)*e^(-2*t) + 1/9*(8*e^9*heaviside(t - 3) + 9*C2)*e^(-3*t) + 1/6*t*heaviside(t - 3) - 5/36*heaviside(t - 3)

y(t)=14(5e6H(t3)4C1)e(2t)+19(8e9H(t3)+9C2)e(3t)+16tH(t3)536H(t3)

(Converting the boundary condituions to sympy is a tad intricate...).

Such conversions to other CAS may be helpful if this CAS is able to gett a closed form of these integral. But that may entail further work to convert these closed forms back to Sage :

sage: solution._mathematica_().sage(locals={"HeavisideTheta":heaviside})
1/36*(9*((2*t - 1)*e^(2*t) - 5*e^6)*e^t*heaviside(t - 3) - 4*((3*t - 1)*e^(3*t) - 8*e^9)*heaviside(t - 3))*e^(-3*t) + 6*e^(-2*t) - 4*e^(-3*t)

136(9((2t1)e(2t)5e6)etH(t3)4((3t1)e(3t)8e9)H(t3))e(3t)+6e(2t)4e(3t)

HTH,

Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 0 years ago

Seen: 53 times

Last updated: Feb 11