Ask Your Question
0

Remove integrals from ODE solved by desolve

asked 2025-02-11 04:25:19 +0100

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)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-02-11 10:08:00 +0100

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)

$$\frac{1}{36} \, {\left(9 \, {\left(2 \, t e^{\left(2 \, t\right)} - 5 \, e^{6} - e^{\left(2 \, t\right)}\right)} e^{t} H\left(t - 3\right) - 4 \, {\left(3 \, t e^{\left(3 \, t\right)} - 8 \, e^{9} - e^{\left(3 \, t\right)}\right)} H\left(t - 3\right)\right)} e^{\left(-3 \, t\right)} + 6 \, e^{\left(-2 \, t\right)} - 4 \, e^{\left(-3 \, t\right)}$$

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)

$$\frac{1}{36} \, {\left(9 \, {\left(2 \, t e^{\left(2 \, t\right)} - 5 \, e^{6} - e^{\left(2 \, t\right)}\right)} e^{t} H\left(t - 3\right) - 4 \, {\left(3 \, t e^{\left(3 \, t\right)} - 8 \, e^{9} - e^{\left(3 \, t\right)}\right)} H\left(t - 3\right)\right)} e^{\left(-3 \, t\right)} + 6 \, e^{\left(-2 \, t\right)} - 4 \, e^{\left(-3 \, t\right)}$$

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)

$$\frac{1}{36} \, {\left(9 \, {\left(2 \, t e^{\left(2 \, t\right)} - 5 \, e^{6} - e^{\left(2 \, t\right)}\right)} e^{t} H\left(t - 3\right) - 4 \, {\left(3 \, t e^{\left(3 \, t\right)} - 8 \, e^{9} - e^{\left(3 \, t\right)}\right)} H\left(t - 3\right)\right)} e^{\left(-3 \, t\right)} + 6 \, e^{\left(-2 \, t\right)} - 4 \, e^{\left(-3 \, t\right)}$$

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\left(t\right) = -\frac{1}{4} \, {\left(5 \, e^{6} H\left(t - 3\right) - 4 \, C_{1}\right)} e^{\left(-2 \, t\right)} + \frac{1}{9} \, {\left(8 \, e^{9} H\left(t - 3\right) + 9 \, C_{2}\right)} e^{\left(-3 \, t\right)} + \frac{1}{6} \, t H\left(t - 3\right) - \frac{5}{36} \, H\left(t - 3\right)$$

(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)

$$\frac{1}{36} \, {\left(9 \, {\left({\left(2 \, t - 1\right)} e^{\left(2 \, t\right)} - 5 \, e^{6}\right)} e^{t} H\left(t - 3\right) - 4 \, {\left({\left(3 \, t - 1\right)} e^{\left(3 \, t\right)} - 8 \, e^{9}\right)} H\left(t - 3\right)\right)} e^{\left(-3 \, t\right)} + 6 \, e^{\left(-2 \, t\right)} - 4 \, e^{\left(-3 \, t\right)}$$

HTH,

edit flag offensive delete link more

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: 2025-02-11 04:25:19 +0100

Seen: 53 times

Last updated: Feb 11