Now we are ready to solve this problem. Here are the general steps we'll follow:

  1. Write a mathematical representation of the scenario. That is, translate the story into a differential equation.
  2. Solve the differential equation.
  3. Interpret the results which may include:
    a) checking that all the requirments are met,
    b) experimenting with different input,
    c) comparing different solutions,
    d) modifying the model!,
    e) etc.
  4. Report.

Representation

Let $q$ be the amount of drug in the blood stream. This is always changing, so we are interested in $\frac{dq}{dt}$ . The derivative, $\frac{dq}{dt}$, is affected by two things:

  • injection of more of the drug: this is what you graphed in exercise 1, let's call the amount of drug in the bloodstream $f(t)$
  • decay of the drug in the blood stream: at the rate of 50% of the amount present, and
\begin{align*} \frac{dq}{dt}&= \mathrm{rate\ in} - \mathrm{rate \ out}\\ &=f(t) - k\cdot q \end{align*}

That's it! We've represented (modeled) the scenario with mathematics.

Solution

The "solution" to a differential equation is a function. In this case, we'd like to know what $q(t)$ is. Sometimes we'll be able to find an algebraic representation for $q(t)$. Sometimes we'll be able to find a numerical solution . Sometimes general behavior will be the form of our solution, eg. "What happens to $q(t)$ as $t \rightarrow \infty$?"

In this scenario we're going to find an algebraic solution, i.e. a formula. Let's think about what we'll need to do:

  1. Notice there is a constant of proportionality in the differential equation. We'll need to find a value for $k$.
  2. We'll need to find a way to represent the functions $f(t)$ you graphed in exercise 1.
  3. Then we'll need to find a technique to solve the differential equation. There are many ways to do this. We'll use a tool called the Laplace transform.

Decay Part

If we suppose for a minute that $f(t)=0$, then the differential equation simplifies to $\frac{dq}{dt}=-kq.$

You may have seen this kind of differential equation in Calc II. It's separable because we can "separate" the $q$ part from the $t$ part and then (more or less) integrate:

\begin{align*} \frac{dq}{dt}&=-kq\\ \frac{1}{q}\ dq &= -k dt\\ \int \frac{1}{q}\ dq &= \int -k dt\\ \ln |q| &= -kt+C\\ q&=e^{-kt+C}\\ q(t)&=Ce^{-kt}\\ \end{align*}

If $t=0$ we have $q(t)=C\cdot e^{0}=C$. So $C$ is the intial quantity, let's call this value $q_0$. We have $q(t)=q_0e^{-kt}.$

In [9]:
clear all
syms t k q(t) q_0
de=diff(q,t)==-k*q
soln(t)=dsolve(de, q(0)==q_0)
 
de(t) =
 
diff(q(t), t) == -k*q(t)
 
 
soln(t) =
 
q_0*exp(-k*t)
 

Now, remember:

The drug is absorbed into the tissues where it does its work at the rate of 50% of the amount present in the bloodstream per hour.

So, $q(1)=\frac{1}{2}\cdot q_0$ and we can find $k$: \begin{align*} q(1)&=\frac{1}{2}\cdot q_0\\ q_0\cdot e^{-k\cdot 1}&=\frac{1}{2}\cdot q_0\\ e^{-k}&=\frac{1}{2}\\ k&=-\ln\left(\frac{1}{2}\right)\\ \end{align*}

(Matlab uses "log" for "ln", "log10" for "log", and "log2" for "log base 2")

In [10]:
eqtn=soln(1)==(1/2)*q_0
solve(eqtn,k)
 
eqtn =
 
q_0*exp(-k) == q_0/2
 
 
ans =
 
log(2)
 

Another example - of solving a separable differential equation

Let's solve $$x \frac{dy}{dx} +y^2+y=0$$ with the initial condition $$y(1)=-2.$$

solution on the board

In [ ]:
clear all
syms x y(x)
de=x*diff(y(x),x)+y^2+y==0
dsolve(de)
soln(x)=dsolve(de, y(1)==-2)
In [ ]:
fplot(soln)
box off
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
ylim([-30,30])

More examples?

$$\frac{dy}{dx} \ln|y|+x^2y=0$$$$\frac{dy}{dx}=2y-y^2, \phantom{space} y(0)=1$$

(Trench, 2.2 #4, #20)

In [ ]:
clear all
syms x y(x)
de=diff(y(x),x)*log(y)+x^2*y(x)==0
dsolve(de)
In [7]:
clear all
syms x y(x)
de=diff(y(x),x)==2*y(x)-y(x)^2
dsolve(de, y(0)==1)
%pretty(dsolve(de))
 
de =
 
diff(y(x), x) == 2*y(x) - y(x)^2
 
 
ans =
 
2/(exp(-2*x) + 1)
 

When we see new techniques for solving differential equations, I'll include references to open source textbooks where you can read more about the techniques. I will also assign homework problems from these textbooks. You can find links to the textbooks on Canvas.

The references will look like this:

  • Trench, section 2.2, pages 45 - 55 (the page number of the book, your viewer may format the pages differently)
  • Nagy, section 1.3.1, pages 21 - 26

Homework:

Solving separable differential equations by hand:

Trench, section 2.2, page 52: 1, 4, 6 (for these three you don't need to solve for $y$, leave it as an implicit solution), 11, 15 (just solve part)

Nagy, section 1.3, page 32: 1.3.1, 1.3.2, 1.3.3, 1.3.4

Solve the following using Matlab. Make sure to think carefully about what the output is telling you!

Trench, section 2.2, page 52: 6, (try 6 and then see cells below) 12 (try the command simplify on #12)

Concerning Trench #6:

You always have to read Matlab results critically. If you solve #6 as below: (execute it)

In [ ]:
clear all
syms x y(x)
de=x^2*y(x)*diff(y(x),x)==(y(x)^2-1)^(3/2)
dsolve(de)

...then something seems wrong with the solutions Matlab provides. Why?

For this example you can give Matlab a little help to find the missing solutions. Do the following:

  1. Separate the variables by hand - so you have $y$s on one side (left) and $x$s on the other (right).
  2. Call these g(y) and f(x) respectively.
  3. Have Matlab integrate these two functions.
  4. Modify $\int f(x) \ dx$ by adding the constant, $C$, on integration.
  5. Set your two results equal to each other and solve for $y$

I've given you a partially completed input box for the process described above. Fill in the missing parts.

In [ ]:
clear all
syms x y C  %% Notice the variable is y and not y(x) 
g(y)= %Fill in this spot
f(x)= %Fill in this spot
lhs(y)= %Fill in this spot....NOTICE it's lhs(y), not just lhs, this is important!
rhs(x)= %Fill in this spot
rhs(x)=rhs(x)+C
solve(%Fill in the equation here% ,y)