Let's review our progress so far.
We want to solve $$\frac{dq}{dt}=f(t)-kq.$$
We found the value of $k$ and algebraic representations for $f(t)$.
We're ready for the main tool in the scenario:
The Laplace transform transforms calculus problems (differential equations) into algebra problems. The algebra problem is easy, if sometimes messy. If we can undo the transform, take the inverse Laplace transform, we'll have the solution to the differential equation. It's the last step that is the hardest (sometimes impossible).
We'll use the following notation:
$\mathscr{L}(f(t))=F(s)$
The independent variable in the differential equation is $t$, we say the differential equaiton is in the time domain. The Laplace transform has a different independent variable: $s$. The transformed equation is said to be in the frequency domain.
To help with the notation we'll use lower case letters ($q$, $f$) for functions in the time domain, and upper case letters ($Q$, $F$) for functions in the frequency domain.
Ok, so what is the Laplace transform?
$$\mathscr{L}(f(t))=\int_0^\infty f(t)e^{-st} \ dt.$$This might seems like a bad deal: trading a simple looking differential equation for an awful looking, improper integral.
Don't worry!
Let's do an example with the drug administration given by $f(t)=h(t)-h(t-1/2)$. (Just one, 1/2-hour, administration.)
\begin{align*} \frac{dq}{dt}&=f(t)-kq=h(t)-h(t-1/2)-kq\\ \mathscr{L}\left(\frac{dq}{dt}\right)&=\mathscr{L}\left(h(t)-h\left(t-\frac{1}{2}\right)-kq\right)\\ \mathscr{L}\left(\frac{dq}{dt}\right)&=\mathscr{L}\left(h(t)\right)-\mathscr{L}\left(h(t-\frac{1}{2})\right)-k\mathscr{L}\left(q\right)\\ \end{align*}First important property of the Laplace transform: it's linear. So, it's easy to deal with addition, subtraction, and multiplication by constants. BUT: NOT multiplication of functions. Just like derivatives and integrals.
syms t s
syms h(t)
h(t)=heaviside(t);
laplace(h,t,s)
syms g(t)
g(t)=h(t-3)
laplace(g,t,s)
syms t q(t) f(t) s Q Qs k
%k=log(1/2)
f(t)=heaviside(t)-heaviside(t-(1/2))
de=diff(q,t)==f(t)-k*q
transform=laplace(de, t, s)
transform=subs(transform, laplace(q(t),t,s), Q)
Qs=solve(transform, Q)
Qs=subs(Qs, q(0), 2)
pretty(Qs)
and similarly:
\begin{align*} \mathscr{L}(e^{at})&=\frac{1}{s-a}\\ \mathscr{L}(h(t-\tau))&=\frac{e^{-s \tau}}{s}\\ \mathscr{L}(f(t-\tau)h(t-\tau))&=e^{-s \tau}\cdot \mathscr{L}(f(t))\\ \end{align*}See Trench pages 463 and 464 for a table of Laplace transforms.
$\displaystyle \mathscr{L}(e^{2t}-3e^t)=\frac{1}{s-2}-3\frac{1}{s-1}$
$\displaystyle \mathscr{L}(\cos(3t))=\frac{s}{s^2+4}$
another example: Trench 8.1.5b)
Let: $$ f(t) = \begin{cases} t & 0 \leq t \leq 1 \\ 1 & t \geq 1 \\ \end{cases} $$
Write: \begin{align*} f(t)&=t(h(t)-h(t-1))+h(t-1)\\ &=th(t)-th(t-1)+h(t-1)\\ \end{align*}
So, find:
\begin{align*} \mathscr{L}(f(t))&=\mathscr{L}(th(t))-\mathscr{L}(th(t-1))+\mathscr{L}(h(t-1))\\ &=\mathscr{L}(th(t))-\mathscr{L}((t-1+1)h(t-1))+\mathscr{L}(h(t-1))\\ &=\mathscr{L}(th(t))-\mathscr{L}((t-1)h(t-1))-\mathscr{L}((1)h(t-1))+\mathscr{L}(h(t-1))\\ &=\frac{1}{s^2}-\frac{e^{-s}}{s^2} \end{align*}syms t
f(t)=t*(heaviside(t)-heaviside(t-1))+h(t-1)
fplot(f(t), "LineWidth",3)
xlim([-1 5])
F=laplace(f(t), t, s)
By hand: Trench section 8.1: 1b)c)e), 5b)d) Trench section 8.3: 7, 17 BUT just find the Laplace transform and STOP Trench section 8.5: BUT just find the Laplace transform and STOP Trench section 8.7: 6 BUT just find the Laplace transform and STOP
With Matlab: 2c)g)h), 5a)