These exercises are mostly taken from: *Calculus Volume 1 from OpenStax, Print ISBN 193816802X, Digital ISBN 1947172131, https://www.openstax.org/details/calculus-volume-1*

Find the inverse \(f^{-1}\) for the following functions

- \(f(x) = \frac{3x}{x - 2}\)
- \(f(x) = 3x^2 + 2, \ x \geq 0\)
- \(f(x) = 4\sin(x)\)

*In case you need a little hint.*

**Solution**

- \(f(x) = \frac{3x}{x - 2}\) \[\begin{gather} y = \frac{3x}{x - 2} \\ yx - 2y = 3x \\ (y-3)x = 2y \\ x = \frac{2y}{y-3} \end{gather}\] The inverse function is \(f^{-1}(x) = \frac{2x}{x-3}\) with the domain \(\{x | x \neq 3 \}\) and the range \(\{y | y \neq 2 \}\).

- \(f(x) = 3x^2 + 2, \ x \geq 0\) \[\begin{gather} y = 3x^2 + 2 \\ x = \sqrt{\frac{y}{3} - \frac{2}{3}} = \sqrt{\frac{1}{3}} \sqrt{y-2}\\ \end{gather}\] The inverse function is \(f^{-1}(x) = \sqrt{\frac{1}{3}} \sqrt{x-2}\) with the domain \(\{x | x \geq 2 \}\) and the range \(\{y | y \geq 0 \}\).

- \(f(x) = 4\sin(x)\)

This is a periodic function which has \(f(x_1) = f(x_2)\) for multiple \(x_1 \neq x_2\). It is not one-to-one and does not have inverse.

**Note:** The inverses \(\sin^{-1}(x) = \arcsin(x)\) exist on the restricted domain \(-\pi/2 \leq x \leq \pi/2\). The inverses \(\cos^{-1}(x) = \arccos(x)\) exist on the restricted domain \(0 \leq x \leq \pi\).

Use the graphing tool Geogebra to explore the graphs of the following pairs of functions:

- \(h(x) = x^4, \ g(x) = 4^x\)
- \(h(x) = x^{1/2}, \ g(x) = (\frac{1}{2})^x\)
- \(h(x) = e^x, \ g(x) = x!\)
- \(h(x) = \log(x), \ g(x) = x \quad\)
- \(h(x) = \sqrt{x}, \ g(x) = \log_2(x)\)

In which regions (for which intervals of \(x\)) is \(h(x) \geq g(x)\) and where is \(h(x) \leq g(x)\)?

What happens as \(x \to \infty\)?

*A few hints for Geogebra are here.*

**Solution**

The probability density function of the normal distribution has the form

\[f(x) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}} \enspace ,\] where \(\mu\) is the mean of the distribution and \(\sigma^2\) is the variance. The normal probability distribution is usually denoted as \(N(\mu, \sigma^2)\).

Find the density of the normal distribution \(N(3,4)\) at \(x=2.5\). Use python as a calculator to get the result. (There are more exercises later asking you to use this function so you may want to save your code for later reuse.)

Use Geogebra to plot the distribution function and verify your result.

**Note: We will be using the normal probability distribution in the course a lot so it is important that you are at ease working with its density function.**

**Solution**

```
import math
mu = 3
sigma = 2
x = 2.5
(sigma*math.sqrt(2*math.pi))**(-1) * math.exp(-(x-mu)**2/(2*sigma**2))
```

`## 0.19333405840142462`

Solve the following equations for \(x\):

- \(5^x = 2\)
- \(e^x e^{-2} = 3/2\)
- \(e^{3x} - 15 = 0\)
- \(\log(1/x) = 4\)

*In case you need a little hint.*

**Solution**

- \(5^x = 2 \Rightarrow x = \log_5 2 = 0.43\)
- \(e^x e^{-2} = 3/2 \Rightarrow e^{(x-2)} = 3/2 \Rightarrow \log(e^{(x-2)}) = \log(3/2) \Rightarrow (x-2) = \log(3/2) \Rightarrow x = \log(3/2) + 2 = 2.405\)
- \(e^{3x} - 15 = 0 \Rightarrow e^{3x} = 15 \Rightarrow 3x = \log 15 \Rightarrow x = \frac{1}{3} \log 15 = \log \sqrt[3]{15} = 0.902\)
- \(\log(1/x) = 4 \Rightarrow 1/x = e^4 \Rightarrow x = e^{-4} = 0.018\)

Use the properties of logarithms (listed in section 2.6.2.2 here) to write the expressions below as sums or differences of logarithms and simple numbers.

- \(\log x^4 y\)
- \(\log \frac{e^2 a^3}{b}\)
- \(\log \sqrt{x y^3}\)

**Solution**

- \(\log x^4 y = \log x^4 + \log y = 4 \log x + \log y\)
- \(\log \frac{e^2 a^3}{b} = \log (e^2 a^3) - \log b = \log e^2 + \log a^3 - \log b = 2 + 3 \log a - \log b\)
- \(\log \sqrt{x y^3} = \log (x y^3)^{1/2} = \frac{1}{2}\log (x y^3) = \frac{1}{2}(\log x + 3 \log y)\)

Solve the following equations for \(x\):

- \(\log_4(x+2) + \log_4(x-1) = 0\)
- \(\log x + \log(x-2) = \log 4\)

**Solution**

- \[\begin{gather} \log_4(x+2) - \log_4(x-1) = 0 \\ \log_4(x+2) = \log_4(x-1) \\ x+2 = x-1 \Rightarrow \text{ no solution } \end{gather}\]

- \[\begin{gather} \log x + \log(x-2) = \log 4 \\ \log x(x-2) = \log 4 \\ x(x-2) = 4 \\ x^2 - 2x - 4 = 0 \\ x = \frac{2 \pm \sqrt{4 + 16}}{2} = \frac{2 \pm \sqrt{20}}{2} = \frac{2 \pm \sqrt{4*5}}{2} = \frac{2 \pm 2\sqrt{5}}{2} = 1 \pm \sqrt{5} \end{gather}\]

But \(\log(x)\) function has domain \(\{x| x>0\}\) and therefore **the only valid solution is \(x = 1 + \sqrt{5}\)**.

(\(\log(x)\) is not defined for \(x = 1 - \sqrt{5}\).)

The normal probability density function is in some situations called likelihood. As you can see, it is not so easy to work with, because the input variable \(x\) is within the exponent of \(e\).

Therefore in machine learning we often times work with its logarithm \(\log f(x)\) called the *log likelihood*.

Use the properties of logarithms to simplify the log likelihood function into sums or differences of terms for the probability distributions

- \(N(0, 1)\)
- \(N(3, 4)\)

Get the values of the log likelihood functions at point \(x = 2.5\).

**Solution**

\[f(x) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}} \]

\[\log f(x) = -\log \sigma -\frac{1}{2} \log 2\pi - \frac{(x-\mu)^2}{2\sigma^2} \]

```
import math
mu = 0
sigma = 1
x = 2.5
-math.log(sigma) - 0.5*math.log(2*math.pi) -(x-mu)**2/(2*sigma**2)
```

`## -4.043938533204672`

```
import math
mu = 3
sigma = 2
x = 2.5
-math.log(sigma) - 0.5*math.log(2*math.pi) -(x-mu)**2/(2*sigma**2)
```

`## -1.643335713764618`

Write the first few terms (at least 5) of the sequences below:

- \(a_1 = 3, \ a_n = 2a_{n-1} + n \text{ for } n \geq 2\)
- \(a_1 = 1, \ a_2 = 1, \ a_n = a_{n-1} + a_{n-2} \text{ for } n \geq 3 \text{ (Fibonacci)}\)
- \(a_1 = 2, \ a_n = \frac{1}{4}a_1 + \frac{3}{4} \text{ for } n \geq 2\)
- \(a_1 = 1, \ a_2 = 1/2, \ a_n = \frac{a_{n-2}}{a_{n-1}} \text{ for } n \geq 3\)

What is the limit behavour of the series as \(n \to \infty\)?

Are the series converging or diverging?

*Note: A rigorous mathematical approach would be to find the algebraic form of the sequence and then find the limit (if it exists). We are in a machine learning course so we can cheat a little and rely on our intuition.*

**Solution**

- \(\{a_n\} = \{3, 8, 19, 42, 89, \ldots\}\), grows to \(\infty\), diverging
- \(\{a_n\} = \{1, 1, 2, 3, 5, 8, \ldots\}\), grows to \(\infty\), diverging
- \(\{a_n\} = \{2, \frac{5}{4}, \frac{17}{16}, \frac{65}{64}, \frac{257}{256}, \ldots\}\), goes to \(1\), converging
- \(\{a_n\} = \{1, \frac{1}{2}, 2, \frac{1}{4}, 8, \frac{1}{16}, \ldots\}\), alternating, diverging

For the Fibonacci sequence from above, use python to calculate

\[\prod_{n=1}^{10} a_n\]

**Solution**

```
import numpy as np
fib_seq = np.zeros(10)
fib_seq[0] = 1
fib_seq[1] = 1
for i in range(2,10):
fib_seq[i] = fib_seq[i-1] + fib_seq[i-2]
np.prod(fib_seq)
```

`122522400.0`

We have four **independent** random normal variables distributed as \(X_1 \sim N(0,1)\), \(X_2 \sim N(3,4)\), \(X_3 \sim N(1,2)\), \(X_4 \sim N(2.5,9)\).

How do you calculate the joint probability density for all the variables taking the value \(2.5\)? \[f(X_1 = 2.5, X_2 = 2.5, X_3 = 2.5, X_4 = 2.5) = \ ?\] Replace the question mark with the correct way to calculate the joint probability density using the correct mathematical notation. You should use the letter \(X\) only once in the whole term.

Use python and the normal probability density function from E13 to evaluate the joint probability density.

*In case you need a little hint.*

**Solution**

\[f(X_1 = 2.5, X_2 = 2.5, X_3 = 2.5, X_4 = 2.5) = \prod_{i=1}^4 f(X_i = 0.25)\]

```
import numpy as np
import math
x = 2.5
def norm_distrib(x, mu, sigma):
return (sigma*math.sqrt(2*math.pi))**(-1) * math.exp(-(x-mu)**2/(2*sigma**2))
probs = np.zeros(4)
probs[0] = norm_distrib(x, 0, 1)
probs[1] = norm_distrib(x, 3, 2)
probs[2] = norm_distrib(x, 1, 2**(0.5))
probs[3] = norm_distrib(x, 2.5, 3)
np.prod(probs)
```

`7.243382349449352e-05`

Imagine an experiment (such as tossing a coin) with only two possible outcomes (e.g. success/failure, yes/no, true/false, heads/tails) and the probability of a positive outcome \(p\) (e.g. when tossing a coin, the probability of getting head is \(p = 0.5\))

The binomial distribution gives the probability of the number of successes \(k\) if you repeat the same experiment \(n\) times in a row (e.g. \(k\) is the number of heads you will get if you toss a coin \(n\) times.).

\[P(k) = {n \choose k} p^k (1-p)^{n-k}\] What is the probability \(P(k)\) of getting 3 positive outcomes when repeating 8 times an experiment with the success probability \(p=0.7\)? Use python as a calculator.

**Solution**

\[\begin{eqnarray} P(k=3) & = & {8 \choose 3} 0.7^3 (1-0.7)^{8-3} \\ & = & \frac{8!}{3!5!} 0.7^3 0.3^5 \\ & = & \frac{8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1}{(3 \times 2 \times 1)(5 \times 4 \times 3 \times 2 \times 1)} 0.7^3 0.3^5 \\ & = & \frac{8 \times 7 \times 6}{3 \times 2} 0.7^3 0.3^5 = 0.0467 \end{eqnarray}\]