title: In MATLAB, How Do I Substitute Initial Value for Derivative in Laplace Transform?
body: <p>I have a .m script for working with inhomogeneous first-order linear IVP with constant coefficients in MATLAB; I'll use $\dot{x} - 3x = t^2$, $x(0) = 4$ as an example:</p>
  
  <pre><code>syms x(t) s X
  Dx = diff(x(t),t)
  ode = Dx - 3*x - t^2
  x0 = 4
  
  ODE = laplace(ode,t,s) % The t and s in laplace aren't necessary, as they are default
  IVP = subs(ODE,{x(0)},{x0})
  IVP = subs(IVP,{laplace(x(t),t,s)},{X})
  IVP = collect(IVP,X)
  
  X = solve(IVP, X)
  X = partfrac(X)
  
  sol = ilaplace(X, s, t)
  
  Dsol = diff(sol,t)
  check1 = Dsol - 3*sol
  check2 = vpa(subs(sol, t, 0))
  </code></pre>
  
  <p>That works fine.</p>
  
  <p>When I try to do a variation on this script for a second-order linear IVP with constant coefficients, I get stumped trying to substitute in for the value of the first derivative at t = 0 (using $\ddot{x} - 2\dot{x} - 3x = t^2$, $x(0) = 4$, $\dot{x} = 5$ as an example):</p>
  
  <pre><code>syms x(t) s X
  Dx = diff(x,t)
  D2x = diff(x, t, 2)
  ode = D2x - 2*Dx - 3*x - t^2
  x0 = 4
  xdot0 = 5
  
  ODE = laplace(ode,t,s)
  IVP = subs(ODE,{x(0)},{x0})
  IVP = subs(ODE,{D(x)(0)},{xdot0}) % &lt;- &lt;- THIS IS THE PROBLEM LINE!!
  IVP = subs(IVP,{laplace(x(t),t,s)},{X})
  IVP = collect(IVP,X)
  
  X = solve(IVP, X)
  X = partfrac(X)
  
  sol = ilaplace(X, s, t)
  
  Dsol = diff(sol,t)
  D2sol = diff(sol, t, 2)
  check1 = D2sol - 2*Dsol - 3*sol
  check2 = vpa(subs(sol, t, 0))
  check3 = vpa(subs(Dsol, t, 0))
  </code></pre>
  
  <p>I'm not sure what to put as the variable D(x)(0) in the Laplace transform of the second derivative; everything I've tried gives me some kind of error or another. I had to resort to the kludgy</p>
  
  <pre><code>syms x(t) s X
  
  a1 =-2
  a0 = -3
  x0 = 4
  xdot0 = 5
  rhs = t^2
  
  Dx = diff(x,t)
  D2x = diff(x,t,2)
  lhs = D2x + a1*Dx + a0*x
  ode = lhs - rhs
  
  Lx = X 
  LDx = s*X - x0
  LD2x = s^2*X - x0*s - xdot0
  LHS = LD2x + a1*LDx + a0*Lx
  RHS = laplace(rhs,t,s)
  IVP = LHS - RHS
  
  IVP = collect(IVP,X)
  
  X = solve(IVP, X)
  X = partfrac(X)
  
  sol = ilaplace(X, s, t)
  
  Dsol = diff(sol,t)
  D2sol = diff(sol,t,2)
  check1 = D2sol + a1*Dsol + a0*sol
  check2 = vpa(subs(sol, t, 0))
  check3 = vpa(subs(Dsol, t, 0))
  </code></pre>
  
  <p>using a suggestion from <a href="https://math.stackexchange.com/questions/2160177/laplace-transform-of-differential-equations-using-matlab">here</a>. All I really need to know is what to put in for "D(x)(0)". I tried 'D(x)(0)', diff(x,t)(0), Dx(0),</p>
  
  <pre><code>help = D(x)
  IVP = subs(ODE,{help(0)},{xdot0})
  
  help2 = diff(x,t)
  IVP = subs(ODE,{help2(0)},{xdot0})
  </code></pre>
  
  <p>you name it, nothing worked.</p>
  
  <p>Thanks in advance for any assistance you can provide.</p>