352 - Topic 16 - Laplace Transforms and Discontinuity of forcing terms

29 days ago by Professor352

John Travis

Mississippi College

Playing around with the effects of an impulse forcing term in a second order differential equation.

@interact def _(y0 = slider(1,5,1/10,1,label='$y(0)$'),stepped = slider(1,10,1/10,2,label='Impulse time'), A = slider(-5,5,1/2,3/2,label='Impulse amount')): y0p= 0 html("Solve $y^{''}+2y^{'}+2y = %s$"%str(latex(A))+"$\delta(t-%s)$"%str(latex(stepped))) var('t') y = y0*e^(-t)*(sin(t))+A*e^(-(t-stepped))*sin(t-stepped)*unit_step(t-stepped) G = text('impulse',(stepped,0.1),color='red')+plot(y,(t,0,stepped*5)) G.show() 
       

Click to the left again to hide and once more to show the dynamic interactive window

# Thus far, sage (via maxima) cannot handle inverse laplace transforms involving delta functions var('t,s,y0,yp0') y=function('y')(t) eq = diff(y,t,2)+2*diff(y,t,1)+2*y==3*unit_step(t-2) # eq = diff(y,t,2)+2*diff(y,t,1)+2*y==3*dirac_delta(t-2) # desolve_laplace(eq,y,ics=[0,5,0]) desolve_laplace(eq,y) 
       
ilt(((g2842^2*y(0) + g2842*(2*y(0) + D[0](y)(0)))*e^(2*g2842) +
3)*e^(-2*g2842)/(g2842^3 + 2*g2842^2 + 2*g2842), g2842, t)
ilt(((g2842^2*y(0) + g2842*(2*y(0) + D[0](y)(0)))*e^(2*g2842) + 3)*e^(-2*g2842)/(g2842^3 + 2*g2842^2 + 2*g2842), g2842, t)
# This is supposed to work transformeq = laplace(eq,t,s) transformeq.show() from sage.all import * transform = laplace_transform(eq, t, s, y(0) == y0, y(0).diff(t) == yp0) F = solve(transform,transform)[0] transform.show() 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'laplace_transform' is not defined
Traceback (most recent call last):    transform.show()
  File "", line 1, in <module>
    
  File "/tmp/tmpNcLX82/___code___.py", line 6, in <module>
    transform = laplace_transform(eq, t, s,  y(_sage_const_0 ) == y0, y(_sage_const_0 ).diff(t) == yp0)
NameError: name 'laplace_transform' is not defined
# This is indeed copied from sagemath.org from sage.all import * t, s = var('t s') # Define variables y = function('y')(t) # Define function 'y' as a function of 't' # Differential equation de = diff(y, t, 2) + 4*diff(y, t) + 4*y == 0 # Initial conditions y_0 = 1 y_dot_0 = 0 # Apply Laplace transform Y = laplace_transform(de, t, s, y(0) == y_0, y(0).diff(t) == y_dot_0) # Solve the algebraic equation Y_sol = solve(Y, Y)[0] # Inverse Laplace transform y_sol = inverse_laplace_transform(Y_sol, s, t) print("Solution: ", y_sol) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'laplace_transform' is not defined
Traceback (most recent call last):    y = function('y')(t)  # Define function 'y' as a function of 't'
  File "", line 1, in <module>
    
  File "/tmp/tmppBU5Zv/___code___.py", line 29, in <module>
    Y = laplace_transform(de, t, s,  y(_sage_const_0 ) == y_0, y(_sage_const_0 ).diff(t) == y_dot_0)
NameError: name 'laplace_transform' is not defined
var('x,s') y = function('y')(t) g = cos(t) + dirac_delta(t-pi/2) DE = diff(y,t,2) + 2*diff(y,t,1) + 2*y == g Trans = laplace(DE,t,s).simplify() show(DE) # Why does the following not work to the logical end? ICS = [0,0,0] desolve_laplace(DE,y,ics=ICS).simplify().show() show(Trans) TransRHS = laplace(g,t,s) show(TransRHS) Trans = TransRHS/(s^2+2*s + 2) show(Trans) inverse_laplace(Trans,s,t).show() @interact def _(y0 = slider(1,5,1/10,1,label='$y(0)$'),stepped = slider(1,10,1/10,2,label='Impulse time'), A = slider(-5,5,1/2,3/2,label='Impulse amount')): y0p= 0 pretty_print(html("Solve $y^{''}+2y^{'}+2y = %s$"%str(latex(A))+"$\delta(t-%s)$"%str(latex(stepped)))) yanswer = y0*e^(-t)*(sin(t))+A*e^(-(t-stepped))*sin(t-stepped)*unit_step(t-stepped) G = text('impulse',(stepped,0.1),color='red')+plot(yanswer,(t,0,stepped*5)) G.show() 
       
$y(0)$ 
Impulse time 
Impulse amount 

Click to the left again to hide and once more to show the dynamic interactive window