Derivatives, tangents and differential equations

Ivan Cnop
Vrije universiteit Brussel
icnop@vub.ac.be

Derivatives notations

f[x_] := a x^3  +  b x^2  + c x  + d

f'[x]
f'[2]

Beware: this can only be used if no confusion is possible:

D[f[x], x]
D[f[x], x] /. x -> 2

Using palettes

(∂_x) f[x]

Traditional Form is the Leibniz notation:

((∂f(x))/(∂x))

Since Mathematica does not know  f depends on x it is not possible to write

D[f, x]
(∂_x) f
D[f[x], 2]

Slope of a graph

Information from the derivative

Write Log for the natural logaritme  ln

Plot[x Log[x], {x,  .01, 3}, AspectRatio -> Automatic]

g[x_] := x Log[x]

g'[x]

Plot[g'[x], {x,  .01, 3}, AspectRatio -> Automatic]

The right hand limit in  0  is indeed  -∞  :

Limit[g'[x], x -> 0, Direction -> -1]

but convergence is slow so that we do not really see the vertical tangent at the origin

Table[g'[10^-k] // N, {k, 20}] // TableForm

Symbolic computation of derivatives

Square root

(1/((Sqrt[x + h]) + (Sqrt[x]))) 
      Expand[((Sqrt[x + h]) - (Sqrt[x])) ((Sqrt[x + h]) + (Sqrt[x]))]

Limit[%/h, h -> 0]

powers

Simplify[(Expand[(x + h)^10] - x^10)/h ]

Limit[%, h -> 0]

Short[Series[(x + h)^n, {h, 0, 10}]]

Subtract   (x^n) , divide by   h   and take limit

Normal[%] - x^n

Limit[%/h, h -> 0]

1  over   x

If  x  is different from   0

Together[1/(x + h) - 1/x]

Limit[%/h, h -> 0]

Applications

Movement

Do[ParametricPlot[{1, 20 t - 4.9 t^2}, {t, nu, nu +  .2}, 
        PlotRange -> {{0, 6}, {0, 25}}], {nu, 0, 4,  .2}]

Do[ParametricPlot[{t, 20 t - 4.9 t^2}, {t, nu, nu +  .2}, 
        PlotRange -> {{0, 6}, {0, 25}}], {nu, 0, 4,  .2}]

Show[{ListPlot[Table[{1, 20 t - 4.9 t^2}, {t, 0, 4,  .2}]], 
        ListPlot[Table[{t, 20 t - 4.9 t^2}, {t, 0, 4,  .2}]]}]

Show[
      Graphics[Table[{Hue[t/4], Point[{t, 20 t - 4.9 t^2}]}, {t, 0, 
            4,  .2}]], Axes -> {True, False}]

Genetics

y[p_] := 2 p (1 - p) + p^2

Plot[y[p], {p, 0, 1}, AspectRatio -> Automatic]

Effect of increasing   p:

Show[{ListPlot[Table[{p, y[p]}, {p, 0,  .9,  .1}]], 
        ListPlot[Table[{p, y[p +  .1]}, {p, 0,  .9,  .1}]]}, 
      Axes -> {True, False} , 
      AspectRatio -> Automatic]

h =  .15

Show[
      Graphics[Table[Line[{{p, y[p]}, {p, y[p + h]}}], {p, 0,  .9,  .1}]], 
      Axes -> {True, False} , 
      AspectRatio -> Automatic]

Plot[y'[p], {p, 0, 1}, AspectRatio -> Automatic]

Economics

c[x_] := x^3/2 - 4 x^2  + 15 x

r[x_] := x^3/2 - 3 x^2  + 12 x

Plot[{c[x], r[x], r[x] - c[x]}, {x, 0, 4}, PlotRange -> All, 
      PlotStyle -> {Hue[0], Hue[0.6], GrayLevel[0.3]}]

Plot[{c[x], r[x], r[x] - c[x]}, {x, 0, 13}, PlotRange -> All, 
      PlotStyle -> {Hue[0], Hue[0.6], GrayLevel[0.3]}]

Plotting marginal return  r  and cost  c  when production is about 10, together with their difference (profit)

Plot[{c[x], r[x], r[x] - c[x]}, {x, 10, 11}, 
      PlotStyle -> {Hue[ .6], Hue[0], GrayLevel[0.3]}]

On small  intervals these look like straight lines.
Where do we have horizontal behavior for profit?

Solve[r'[x] == c'[x], x]

Rules for the derivative

Product

D[f[x] g[x], x]

Can be derived symbolically

definition = {limit[(f_[x_ + h_] - f_[x_])/h, 
            h_ -> 0] :> f'[x], 
limit[
            f_[x_ + h_], h_ -> 0] :> f[x]}

limit[(u[a + h] - u[a])/h, h -> 0] /. definition

limit[u[x + h] , h -> 0] /. definition

Clear[h, f, g, u, v];
(∂_x) (f[x] g[x])

Expand[
      u[x + h] (v[x + h] - v[x])  + (u[x + h] - u[x]) v[
            x]]

divide by   h   and take a limit

limit[u[x + h], h -> 0] /. definition
limit[(v[x + h] - v[x])/h, h -> 0] /. 
      definition
limit[(u[x + h] - u[x])/h, h -> 0] /. 
      definition
v[x]

Applications

Sensitivity to medication

The following model describes the reactiof the body to a given amount of medecine in the blood.

Clear[c, r];
r[m_] := m^2 (c/2 - m/3)

Simplify[(∂_m) r[m]]

c = 4 ; 
    Plot[{r[m], r'[m]}, {m, 0, 5}, Ticks -> {Range[4] , None}, 
      AspectRatio ->  Automatic]

We see that increasing the dosis beyond the steepest slope value does not help  and can result in an adverse effect.

Harmonic movement

(∂_t) Sin[t]

(∂_t) %

% + Sin[t]

(∂_t) Cos[t]

(∂_t) %

% + Cos[t]

(∂_t) (∂_t) (a Cos[t]  +  
            b Sin[t])

% + a Cos[t]  +  b Sin[t]

DSolve[f''[t] + f[t] == 0, f[t], t]

Are the only solutions to this differential equation

a =  .5; b = 2; 
    Plot[a Cos[t]  +  b Sin[t], {t, -2, 8}]

It looks like a translation of a Cos function

Plot[2 Cos[t - 1.5], {t, -2, 8}]

We can actually compute these:

Solve[{a Cos[0]  +  b Sin[0] == A Cos[0 + B], 
        a Cos[1]  +  b Sin[1] == A Cos[1 + B]}, {A, B}]

Plot[A Cos[t + B] /. Last[%], {t, -2, 8}]

Plot[A Cos[t + B] /. First[%%], {t, -2, 8}]

Lissajous figures

ParametricPlot[{Sin[5 t], Sin[4 t]}, {t, 0, 2 Pi}]

Chain rule

Rule

Clear[f, g]

D[f[g[x]], x]

(∂_x) f[g[x]]

Proof

{f[y] - f[y0], f'[y0] (y - y0)} /. {y -> g[x], 
        y0 -> g[x0]}

% /. g[x] - g[x0] -> g'[x0] (x - x0)

First[%] == Last[%]

Graphs given by parametric representation

(∂_x) f[g[x]]

Replace   x   by   t   and    g  by   x.

y[t_] := t - t^3

x[t_] := t - t^2

ParametricPlot[{x[t], y[t]}, {t, -1, 2}, 
      AspectRatio -> Automatic]

((∂y(t))/(∂t))

(((∂y(t))/(∂t))/((∂x(t))/(∂t)))

This rule is simpler than doing the full computation by substitution:

Solve[x == t - t^2, t]

y[t /. Solve[x == t - t^2, t]]

(∂_x) %