Solutions#

Question 1#

  1. For each of the following functions calculate \(\frac{df}{dx}\), \(\frac{d^2f}{dx^2}\) and \(\int f(x) dx\).

\(f(x) = x\)

import sympy as sym

x = sym.Symbol("x")
expression = x
sym.diff(expression, x)
\[\displaystyle 1\]
sym.diff(expression, x, 2)
\[\displaystyle 0\]
sym.integrate(expression, x)
\[\displaystyle \frac{x^{2}}{2}\]

\(f(x) = x ^{\frac{1}{3}}\)

expression = x ** (sym.S(1) / 3)
sym.diff(expression, x)
\[\displaystyle \frac{1}{3 x^{\frac{2}{3}}}\]
sym.diff(expression, x, 2)
\[\displaystyle - \frac{2}{9 x^{\frac{5}{3}}}\]
sym.integrate(expression, x)
\[\displaystyle \frac{3 x^{\frac{4}{3}}}{4}\]

\(f(x) = 2 x (x - 3) (\sin(x) - 5)\)

expression = 2 * x * (x - 3) * (sym.sin(x) - 5)
sym.diff(expression, x)
\[\displaystyle 2 x \left(x - 3\right) \cos{\left(x \right)} + 2 x \left(\sin{\left(x \right)} - 5\right) + 2 \left(x - 3\right) \left(\sin{\left(x \right)} - 5\right)\]
sym.diff(expression, x, 2)
\[\displaystyle 2 \left(- x \left(x - 3\right) \sin{\left(x \right)} + 2 x \cos{\left(x \right)} + 2 \left(x - 3\right) \cos{\left(x \right)} + 2 \sin{\left(x \right)} - 10\right)\]
sym.integrate(expression, x)
\[\displaystyle - \frac{10 x^{3}}{3} - 2 x^{2} \cos{\left(x \right)} + 15 x^{2} + 4 x \sin{\left(x \right)} + 6 x \cos{\left(x \right)} - 6 \sin{\left(x \right)} + 4 \cos{\left(x \right)}\]

\(f(x) = 3 x ^ 3 + 6 \sqrt{x} + 3\)

expression = 3 * x ** 3 + 6 * sym.sqrt(x) + 3
sym.diff(expression, x)
\[\displaystyle 9 x^{2} + \frac{3}{\sqrt{x}}\]
sym.diff(expression, x, 2)
\[\displaystyle 3 \cdot \left(6 x - \frac{1}{2 x^{\frac{3}{2}}}\right)\]
sym.integrate(expression, x)
\[\displaystyle 4 x^{\frac{3}{2}} + \frac{3 x^{4}}{4} + 3 x\]

Question 2#

2. Consider the function \(f(x)=2x+1\). By differentiating from first principles show that \(f'(x)=2\).

Using the definition of the derivative:

h = sym.Symbol("h")
expression = 2 * x + 1
sym.limit((expression - expression.subs({x: x - h})) / h, h, 0)
\[\displaystyle 2\]

Question 3#

3. Consider the second derivative \(f''(x)=6x+4\) of some cubic function \(f(x)\).

1. Find \(f'(x)\)

We know the derivative will be the integral of the second derivative with a constant:

c1 = sym.Symbol("c1")

second_derivative = 6 * x + 4
derivative = sym.integrate(second_derivative, x) + c1
derivative
\[\displaystyle c_{1} + 3 x^{2} + 4 x\]

2. You are given that \(f(0)=10\) and \(f(1)=13\), find \(f(x)\).

We know that the cubic will be the integral of the derivative with constant:

c2 = sym.Symbol("c2")

cubic = sym.integrate(derivative, x) + c2
cubic
\[\displaystyle c_{1} x + c_{2} + x^{3} + 2 x^{2}\]

We substitute \(x=0\):

cubic.subs({x: 0})
\[\displaystyle c_{2}\]

This gives \(c_2=10\). We substitute that back in to our expression for the cubic:

cubic = cubic.subs({c2: 10})
cubic
\[\displaystyle c_{1} x + x^{3} + 2 x^{2} + 10\]

and now substitute \(x=1\):

cubic.subs({x: 1})
\[\displaystyle c_{1} + 13\]

which gives \(c_1=0\) which we substitute back in to our expression for the cubic:

cubic = cubic.subs({c1: 0})
cubic
\[\displaystyle x^{3} + 2 x^{2} + 10\]

3. Find all the stationary points of \(f(x)\) and determine their nature.

The stationary points are the points that give \(\frac{df}{dx}=0\):

stationary_points = sym.solveset(sym.diff(cubic, x), x)
stationary_points
\[\displaystyle \left\{- \frac{4}{3}, 0\right\}\]

We determine the nature of these turning points by considering the sign of \(\frac{d^2f}{dx^2}\) at each point.

second_derivative.subs({x: -4 / sym.S(3)})
\[\displaystyle -4\]

This is negative, so it is a local maximum.

second_derivative.subs({x: 0})
\[\displaystyle 4\]

This is positive, so it is a local minimum.

Question 4#

4. Consider the function \(f(x)=\frac{2}{3}x ^ 3 + b x ^ 2 + 2 x + 3\), where \(b\) is some undetermined coefficient.

1. Find \(f'(x)\) and \(f''(x)\)

b = sym.Symbol("b")
expression = sym.S(2) / 3 * x ** 3 + b * x ** 2 + 2 * x + 3
derivative = sym.diff(expression, x)
derivative
\[\displaystyle 2 b x + 2 x^{2} + 2\]
second_derivative = sym.diff(expression, x, 2)

2. You are given that \(f(x)\) has a stationary point at \(x=2\). Use this information to find \(b\).

We solve the equation that arises when substituting \(x=2\) in to the derivative:

equation = sym.Eq(derivative.subs({x: 2}), 0)
equation
\[\displaystyle 4 b + 10 = 0\]
sym.solveset(equation, b)
\[\displaystyle \left\{- \frac{5}{2}\right\}\]

3. Find the coordinates of the other stationary point.

We substitute this value of \(b\) in to the expression:

b_value = -sym.S(5) / 2
expression = expression.subs({b: b_value})
expression
\[\displaystyle \frac{2 x^{3}}{3} - \frac{5 x^{2}}{2} + 2 x + 3\]

and the derivative and then solve the equation:

derivative = derivative.subs({b: b_value})
sym.solveset(derivative)
\[\displaystyle \left\{\frac{1}{2}, 2\right\}\]

This confirms that one stationary point is indeed at \(x=2\), the other is at \(x=1/2\). To get the full coordinate of this other stationary point we substitute this value of \(x\) in to \(f\):

expression.subs({b: b_value, x: sym.S(1) / 2})
\[\displaystyle \frac{83}{24}\]

4. Determine the nature of both stationary points.

Substituting both values in to the second derivative:

second_derivative = second_derivative.subs({b: b_value})
second_derivative.subs({x: sym.S(1) / 2})
\[\displaystyle -3\]

This is negative so it is a local maxima.

second_derivative.subs({x: 2})
\[\displaystyle 3\]

This is positive so it is a local minima.

Question 5#

5. Consider the functions \(f(x)=-x^2+4x+4\) and \(g(x)=3x^2-2x-2\).

1. Create a variable turning_points which has value the turning points of \(f(x)\).

f = -(x ** 2) + 4 * x + 4
derivative = sym.diff(f, x)
turning_points = sym.solveset(derivative, x)

2. Create variable intersection_points which has value of the points where \(f(x)\) and \(g(x)\) intersect.

g = 3 * x ** 2 - 2 * x - 2
equation = sym.Eq(f, g)
intersection_points = sym.solveset(equation, x)
intersection_points
\[\displaystyle \left\{\frac{3}{4} - \frac{\sqrt{33}}{4}, \frac{3}{4} + \frac{\sqrt{33}}{4}\right\}\]

3. Using your answers to parts 2., calculate the area of the region between \(f\) and \(g\). Assign this value to a variable area_between.

The area between \(f\) and \(g\) corresponds to the integral of \(\pm (f - g)\) between the points of intersection. We here use \(f - g\), if the outcome was negative we would take the opposite.

area_between = sym.integrate(
    f - g, (x, sym.S(3) / 4 - sym.sqrt(33) / 4, sym.S(3) / 4 + sym.sqrt(33) / 4)
)
sym.simplify(area_between)
\[\displaystyle \frac{11 \sqrt{33}}{4}\]