Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following code is working, there is no third power of $x$ involved...

s, t = var('s, t')

# Define the function x(t) and its derivatives
x = function('x')(t)

de = diff(x, t, 3) - 2*diff(x, t, 2) + 5*diff(x, t)
de.laplace(t, s)

This gives so far:

s^3*laplace(x(t), t, s) - 2*s^2*laplace(x(t), t, s)
    - s^2*x(0) + 5*s*laplace(x(t), t, s) 
    + 2*s*x(0) - s*D[0](x)(0) - 5*x(0) + 2*D[0](x)(0) - D[0, 0](x)(0)

The given boundary conditions imply that the transformed function $Lx(s)$ is the function which satisfies the equation: $$ (s^3 -2s^2 +5s)Lx(s) = 1\ . $$

So we have an equation for $Lx$, the solution is obtained by using partial fraction decomposition:

 sage: ( 1/(s^3 - 2*s^2 + 5*s) ).partial_fraction()
-1/5*(s - 2)/(s^2 - 2*s + 5) + 1/5/s

and then transform back, which can be done even directly:

sage: inverse_laplace( 1/(s^3 - 2*s^2 + 5*s), s, t )
-1/10*(2*cos(2*t) - sin(2*t))*e^t + 1/5

Let us test that this is a solution:

sage: X = inverse_laplace( 1/(s^3 - 2*s^2 + 5*s), s, t )
sage: X0, X1, X2, X3 = [diff(X, t, k) for k in [0,1,2,3]]
sage: (X3 - 2*X2 + 5*X1).simplify_full()
0
sage: X.subs(t=0)
0
sage: X1.subs(t=0)
0
sage: X2.subs(t=0)
1