Excercise sheet 4 -- solutions

Derivatives

1. Derivate (x^2) + 4  xwith respect to x
2. Derivate (x^4) + 3  x - sin(x) twice
3. Let the position of a moving body be given by the expression x(t)  =  40 - 5  t - 5  (t^2). What is the position, velocity and the acceleration at t = 2
4. Plot the velocity and position of the previous task in same figure.
5. Does Mathematica know the most common rules for taking derivatives? Find the derivative of
	a.	f(g(x))	(chain rule)
	b.	f(x) g(x)	(derivative of a product)
	c.	((f(x))/(g(x)))		(derivative of a fraction)
6. Let f(x, y) = (x^3) (y^4). Find the partial derivatives
	a. 	∂(f/∂)x, ∂(f/∂)y
	b.	(∂^2) (f/∂)(x^2), (∂^2) (f/∂)(y^2)
	c.	(∂^2) (f/(∂x ∂y)), (∂^2) (f/(∂y ∂x))

Solutions

D[x^2 + 4  x, x]

D[
      x^4 + 3  x - Sin[x], {x, 2}]

x[t_] = 
        40 - 5  t - 5  t^2;

    v[t_] = D[x[t], t];

    a[t_] = D[x[t], {t, 2}];

    x[2]

    v[2]

    a[2]

Plot[{v[t], a[t]}, {t, 0, 4}, 
      PlotStyle -> {Dashing[{0.01}], Dashing[{}]}]

The function Together pulls the terms of a sum over a common denominator.

Clear[f, g]

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

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

    D[f[x]/g[x], x] // Together

Note the syntax for D: When writing D[f[x,y],x,y], the last variable in the list (here y), is the one with respect to which the derivative is calculated first.

f[x_, y_] = 
      x^3 y^4

    D[f[x, y], x]

    D[f[x, y], y]

    D[f[x, y], {x, 2}]

    D[f[x, y], {y, 2}]

    D[f[x, y], x, y]

    D[f[x, y], y, x, y]

Total differential

1.

1. Find the total differential of F(x, y, z) = x y + (z^2) x + y (z^3)
2. Find the total differential of \(TraditionalForm\`G(
          r, \ θ, ϕ) = \(1\/r\^2\) \(sin(θ)\) \(cos(ϕ)\)\).
3. Find the total derivative of F(x,  y) = (Sqrt[(x^2) + (y^2)]),  x = x(t),  
      y = y(t),  with respect to t

Solutions

Dt[x y + z^2 x + y z^3] // 
      Simplify

The greek alphabet can be written as "Esc-theta-Esc", etc. α β γ δ

Dt[
        1/r^2*Sin[θ] Cos[ϕ]] // Simplify

Dt automatically assumes that all symbols are a function of the variable with respect to which the total derivative is calculated. You can override this assumption with Constants->{...}.

Dt[Sqrt[x^2 + y^2], 
      t]

2.

Let U(S, V, N) = T S - p V + μ N.  This is the internal energy of a system with state variables entropy S, volume V and particle number N.

1. Find the total differential of U. 
2. Find the partial derivative ∂(U/∂)Sand ∂(U/∂)V 
3. Find the total derivatives d(U/d) Sand d(U/d)V 
4. Take the total differential of U and set the differentials with respect to T,  p and μ to zero.

Solutions

U[S_, V_, N_] := 
      T S - p V + μ N

    Dt[U[S, V, N]]

    Dt[U[S, V, N], Constants -> {T, p, μ}]

D[U[S, V, N], 
      S]

    D[U[S, V, N], V]

Dt[U[S, V, N], 
      S]

    Dt[U[S, V, N], V]

    Dt[U[S, V, N], S, Constants -> {T, p, μ}]

    Dt[U[S, V, N], V, Constants -> {T, p, μ}]

Dt[
        U[S, V, N]] /. {Dt[T] -> 0, Dt[p] -> 0, 
        Dt[μ] -> 0}

3.

1. Sven-Erik finds a mysterious metal sphere on his lawn. He measures the radius of the sphere three times, and gets as results r = 12.0,  12.1,  11.8 centimeters. Find the volume of the sphere V = (4/3) π (r^3) and the error limits.
2. Let's assume that the number of monkeys at a zoo depends on the number of bananas and the weight of a monkey according to the following formula: m[banana_,weight_]=3*banana/weight. Calculate the number of monkeys and the error limits when there are 100 ± 5 kg of bananas and one monkey weighs 7.3 ± 1.2 kg!

Solutions

Note that most data analysis functions must be loaded from the add-on package Statistics`DescriptiveStatistics`, but the standard procedures, such as calculating the average, minimum or maximum values of a data set are built in. The plusminus sign is typed Esc - +- - Esc. Superscripts are typed Ctrl-6.

rdata = {12.0, 12.1, 11.8};
radius = Mean[rdata];
dr = Max[rdata - radius];
V[r_] = 4/3 Pi r^3;
Print["The volume of the sphere is ",V[radius]," ± ",Abs[Dt[V[r]]] /. {r -> rad, Dt[r] -> dr}," (cm^3)."]

This result would round off to 7200 ± 300  (cm^3).

m[b_, w_] = 3*b/w;
(Subscript[b, av]) = 100;  
        db = 5;
(Subscript[w, av]) = 7.3;  dw = 1.2;
Print["The number of monkeys is ",Round[m[(Subscript[b, av]), (Subscript[w, av])]]," ± ",Ceiling[
                Abs[Part[Dt[m[b, w]], 1]] + 
                  Abs[Part[Dt[m[b, w]], 2]]] /. {b -> (Subscript[b, av]), 
                Dt[b] -> db, w -> (Subscript[w, av]), Dt[w] -> dw},"."]

Integration

1.

1.	Integrate sin(x), x = 0  ...   2  π. Find also the numerical value.
2.	Integrate ln x, check the result by taking its derivative
3.	Find the definite integral (∫_a^b)((∫_c^d) 
                    (1/(x y)) dx) dy. 
4.	A car is speeding at a velocity of v = 15m/s. The police starts chasing the car, accelerating at a = 10  m/(s^2). When does the police catch the speeding man? Plot the positions of both cars as a function of time.
5.	The acceleration of a moving body is given by the expression a(t) = arctan(t), where t is the time in seconds. Find the average velocity over the first twelve seconds, assuming the particle starts at rest at t = 0. What is the velocity after 20 seconds?

Solutions

In the first excercise, NIntegrate complains about something. This is just due to the fact that the exact value of the integral is zero.

Integrate[
      Sin[x], {x, 0, 2  Pi}]

    NIntegrate[Sin[x], {x, 0, 2  Pi}]

Integrate[Log[x], 
      x]

    D[%, x]

The next excercise gives a complicated looking answer. You can simplify the integral with the Assumptions option. Normally, you might assume that the limits of integration are real numbers. Here however the expression Integrate[1/(x y),{y,a,b},{x,c,d},Assumptions->{Element[a,Reals],Element[b,Reals],Element[c,Reals],Element[d,Reals]}] leads to a long computation and eventually to the result If[
        a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            b == 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            a == 0 && b > 0 && a ≥ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            a == 0 && b < 0 && a ≤ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            b > 0 && a ≥ 0 && Im[b] ≠ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            b < 0 && a ≤ 0 && Im[b] ≠ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            a > 0 && b > 0 && Re[b] > 0 && a ≥ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            a > 0 && Re[b] > 0 && b < 0 && a ≤ 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            b > 0 && a ≥ 0 && a < 0 && Re[b] < 0 || 
          a ∈ Reals && c ∈ Reals && d ∈ Reals && 
            a < 0 && b < 0 && Re[b] < 0 && 
            a ≤ 0, (Log[a] - Log[b]) (Log[c] - Log[d]), 
        Integrate[-Log[c]/y + Log[d]/y, {y, a, b}, 
          Assumptions -> 
            a ∈ Reals && b ∈ Reals && c ∈ Reals && 
              d ∈ 
                Reals && ! (a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && b == 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && a == 0 && b > 0 && 
                      a ≥ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && a == 0 && b < 0 && 
                      a ≤ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && b > 0 && a ≥ 0 && 
                      Im[b] ≠ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && b < 0 && a ≤ 0 && 
                      Im[b] ≠ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && a > 0 && b > 0 && Re[b] > 0 && 
                      a ≥ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && a > 0 && Re[b] > 0 && b < 0 && 
                      a ≤ 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && b > 0 && a ≥ 0 && 
                      a < 0 && Re[b] < 0 || 
                    a ∈ Reals && c ∈ Reals && 
                      d ∈ Reals && a < 0 && b < 0 && Re[b] < 0 && 
                      a ≤ 0)]]
That just means that the conditions yield a simpler form in the domain of the complex numbers. A better (though of less generality) assumption is employed below. By the way, the assumption Element[a,Reals] can be written in a shorter form a∈Reals by a-Esc-el-Esc-Reals. Note also that in multiple integrals, the first variable is integrated over last as with the D command.

Clear[a, b, c, 
      d]

    Integrate[1/(x y), {y, a, b}, {x, c, d}]

    Integrate[1/(x y), {y, a, b}, {x, c, d}, 
      Assumptions -> {a > 0, b > 0, c > 0, d > 0, a < b}]

Note the notation in the next excercise. This is reminiscent of hand-written notation, where
	x(t) = 
        x(0) + (Overscript[((∫_0)), t])(v(
                    0) + (Overscript[((∫_0)), t'])a(t'') dt'') 
              dt'
could be written for the position at time t. Here we assume that x = 0is the stakeout place of the police car. The formula
	(Subscript[x, 2])[t_] = Integrate[Integrate[(Subscript[a, 2])[t], t], t]
gives the same result, but violates the formalism!!!

(Subscript[v, 1])[t_] = 15; 
    (Subscript[a, 2])[t_] = 10;

    (Subscript[x, 1])[t_] = Integrate[(Subscript[v, 1])[ti], {ti, 0, t}]

    (Subscript[x, 2])[t_] = 
      Integrate[
        Integrate[(Subscript[a, 2])[tii], {tii, 0, ti}], {ti, 0, t}]

    Solve[(Subscript[x, 1])[t] == (Subscript[x, 2])[t], t]

The average velocity of a particle is
	Δ(x/Δ)t
where Δx is the displacement in the time interval Δt. The basic syntax of Integrate automatically assumes x[0]=0. Fractions are typed Ctrl-/.

\(\(\( (*5*) \)\(
\)\(\(a[t_] = 
        ArcTan[t];\)

    \(v[t_] = Integrate[a[t], t];\)

    \(x[t_] = Integrate[v[t], t];\)

    \(Print[\*""\!\(v\_av\) = "", 
        x[12]/12 // N, \*""\!\(m\/s\)""];\)

    \(Print["v(20s) = ", 
        v[20] // N, \*""\!\(m\/s\)""];\)\)\)\)

Limits and series

1.

Find the following limits
1.	((sin(x))/x),  x -> 0
2.	((Sqrt[1 - (x^2)])/(Sqrt[1 - x])), x -> 1
3. 	(((1 + (x/n)))^n), n -> ∞
4.	\(TraditionalForm\`\(\(2\^\(4  n + 1\)\) \(n!\)\^4\)\/\(\((2  n + 1)\) \(\((2  n)\)!\)\^2\), n -> ∞\)

Solutions

Limit[Sin[x]/x, 
      x -> 0]

Limit[Sqrt[1 - x^2]/Sqrt[1 - x], 
      x -> 1]

Limit[(1 + 1/n)^n, 
      n -> Infinity]

Limit[(2^(4  n + 
                  1) (n!)^4)/((2  n + 
                1) ((2  n)!)^2), 
      n -> Infinity]

2.

1. Find the Taylor series of ((sin(x))/x)up to order 5.
2. Find the Taylor series of sin(x) up to 2nd, 5th, and 9th orders, and plot each of the together with the sine function to the same figure.
3. Expand an undefined function, say f(x), as a power series. What do you find?
4. As an example of a Laurent series, expand the function f(x) = tan(x) as series around the point (Subscript[x, 0]) = π/2. Compare the result to the fraction of the power series of sin(x) and cos(x) expanded around the same point. 
5. Functions can have Laurent series expressions around the point (Subscript[x, 0]) = ∞ also. As an example, find the Laurent series of the function (((Subscript[J, 0])(x))^2) around the point (Subscript[x, 0]) = ∞up to second order. (Subscript[J, 0])(x) is the zeroth order Bessel J function, given in Mathematica by the BesselJ[0,x] function. Plot the series and the original function in same figure.
6. Show that the relativistic expression for energy, E = m (c^2), reduces at the low velocity limit to the non-relativistic kinetic energy, E = (Subscript[m, 0]) (c^2) + (1/2) m (v^2), when we take the relationship between the mass m of a moving body and rest mass (Subscript[m, 0]) to be m = ((Subscript[m, 0])/(Sqrt[1 - ((v^2)/(c^2))])), as given by the theory of relativity.

Solutions

Series[
      Sin[x]/x, {x, 0, 5}]

The function Normal cuts of the O[x^n] term from the series so that it can be plotted.

s1 = 
        Series[Sin[x], {x, 0, 2}] // Normal;

    s2 = Series[Sin[x], {x, 0, 5}] // Normal;

    s3 = Series[Sin[x], {x, 0, 9}] // Normal;

    Plot[{Sin[x], s1, s2, s3}, {x, -2 Pi, 2  Pi}, 
      PlotStyle -> {Hue[0], Hue[1/4], Hue[1/2], 
          Hue[3/4]}]

When the expanded function is undefined, you get the general form of the Taylor's series in terms of the derivatives of the function

Clear[f];

    Series[f[x], {x, y, 5}]

Series[
      Tan[x], {x, Pi/2, 5}]

    Series[Sin[x], {x, Pi/2, 7}]/Series[Cos[x], {x, Pi/2, 7}]

The Bessel function has an essential singularity in infinity (and in an infinite number of other points). For example, the function
	1/((∑_i) (x^i))
has an essential singularity at x = 0. There are terms with an infinite negative exponent.

Series[
        BesselJ[0, x]^2, {x, Infinity, 5}] // Normal

    Plot[{%, BesselJ[0, x]}, {x, 1000, 1020}, 
      PlotStyle -> {Hue[0], Hue[2/3]}]

Clear[m, v, 
        c];

    m[v_] = (Subscript[m, 0])/Sqrt[1 - (v/c)^2];

    Series[m[v] c^2, {v, 0, 3}]