# Laplace: from differential equation to transfer function

First at all, this is trictly related to my own question: How to transform transfer functions into differential equations?

How can I transfer my differential equation into a transfer function?

For me (at the moment) the following works:

TimeDomain2TransferFunction[eqn_, y0_, u0_] :=
Solve[
LaplaceTransform[eqn, t, s] /. y0 /.
u0 /. {LaplaceTransform[y[t], t, s] -> Y[s],
LaplaceTransform[u[t], t, s] -> U[s]}
, Y[s]][[1, 1, 2]]/U[s]


So, let's say the differential equation is

sysEq = y'''[t] == -1/T2^2 y'[t] - T1/T2^2 y''[t] + Ki/T2^2 u[t]


Then the following gives me an satisfying result:

TimeDomain2TransferFunction[sysEq, {y -> 0, y' -> 0,
y'' -> 0}, {}]
ExpandDenominator[%]


Out: $\frac{\text{Ki}}{s \left(s^2 \text{T2}^2+s \text{T1}+1\right)}$

Out: $\frac{\text{Ki}}{s^3 \text{T2}^2+s^2 \text{T1}+s}$

Is there a more elegant way to do this? For example, for different letters (not only y and u).

Is there a more elegant way to do this?

Why not just use the control system functions as is for this? create state space sys from the DE and then use TransferFunctionModel[sys] to obtain the tf:

sysEq = y'''[t] == -1/T2^2 y'[t] - T1/T2^2 y''[t] + ki/T2^2 u[t];
sys = StateSpaceModel[sysEq, {{y[t], 0}}, {{u[t], 0}}, {y[t]}, t];
Simplify@TransferFunctionModel[sys] • Well, that's a good question. I thought there was a reason (because I know these functions), but I can't find it anymore. So, due to the fact that it works for all my systems and it's no hidden function, I prefere your solution.
– Phab
Sep 4, 2014 at 7:53
• Seems like it doesn't work with version 10.2
– Phab
Aug 4, 2015 at 6:59
• @Phab I do not have 10.2, but I just tried it on 10.1 and it works: !Mathematica graphics so I really do not know why it would not work in 10.2. I am waiting for version 11 before I upgrade again. Aug 4, 2015 at 7:50
• "Found" the reason why: It's a bug since 10.0.2.
– Phab
Aug 5, 2015 at 5:34

There's an internal function that does this:

ControlDEqnstransferfunctionForm[sysEq, {{y[t], 0}}, {{u[t], 0}},
y[t], t, s]


The syntax is just like that for the conversion of differential equations to StateSpaceModel, except for an additional last argument that specifies the Laplace variable.

(It doesn't seem to work with delay systems, and for difference equations you need to explicitly specify the sampling period, eg,

ControlDEqnstransferfunctionForm[
y[t + 1] + y[t] == u[t], {{y[t], 0}}, {{u[t], 0}}, y[t], t, z,
SamplingPeriod -> T]


)

• with the exception of the delayed systems, great solution! Where do you/can I find this internal functions?
– Phab
Aug 21, 2014 at 6:15
• These are undocumented, so naturally the best way to hear about them is on sites such as these. Aug 21, 2014 at 14:21

This is not bulletproof but its simpler :-)

eq2 = sysEq /. Derivative[n_][a_][b_] -> s^n a[s]

(*
==>
s^3 y(s) == -((s^2 T1 y(s))/T2^2) - (s y(s))/T2^2 + (χ u(t))/T2^2
*)

First@First@Solve[eq2, y[s]] /. _[t] -> 1

(* ==> y(s) -> χ/(s (s^2 T2^2 + s T1 + 1)) *)

• fails on y[t] == Kp u[t] (also on delayed systems). Also it's not the correct way with replacing u[t] by 1 I think. But interesting syntax, never saw before.
– Phab
Aug 21, 2014 at 6:13