Introduction#

This book aims to introduce readers to programming for mathematics.

It is assumed that readers are used to solving high school mathematics problems of the form:


Problem

Given the function \(f:\mathbb{R}\to\mathbb{R}\) defined by \(f(x) = x ^ 2 - 3 x + 1\) obtain the global minima of the function.

Solution

To solve this we need to apply our mathematical knowledge which tells us to:

  1. Differentiate \(f(x)\) to get \(\frac{df}{dx}\);

  2. Equate \(\frac{df}{dx}=0\);

  3. Use the second derivative test on the solution to the previous equation.

For each of those 3 steps we will usually make use of our mathematical techniques:

  1. Differentiate \(f(x)\):

    \[\frac{df}{dx} = 2 x - 3\]
  2. Equate \(\frac{df}{dx}=0\):

    \[2x-3 =0 \Rightarrow x = 3/2\]
  3. Use the second derivative test on the solution:

    \[\frac{d^2f}{dx^2} = 2 > 0\text{ for all values of }x\]

    Thus \(x=3/2\) is the global minima of the function.

Attention

As we progress as mathematicians mathematical knowledge is more prominent than mathematical technique: often knowing what to do is the real problem as opposed to having the technical ability to do it.

This is what this book will cover: programming allows us to instruct a computer to carry out mathematical techniques.

We will for example learn how to solve the above problem by instructing a computer which mathematical technique to carry out.

This book will teach us how to give the correct instructions to a computer.

The following is an example, do not worry too much about the specific code used for now:

Differentiate \(f(x)\) to get \(\frac{df}{dx}\)#

import sympy as sym

x = sym.Symbol("x")
sym.diff(x ** 2 - 3 * x + 1, x)
\[\displaystyle 2 x - 3\]

Equate \(\frac{df}{dx}=0\)#

sym.solveset(2 * x - 3, x)
\[\displaystyle \left\{\frac{3}{2}\right\}\]

Use the second derivative test on the solution#

sym.diff(x ** 2 - 3 * x + 1, x, 2)
\[\displaystyle 2\]

Knowledge versus technique is a brief summary.

../../_images/main23.png

Fig. 1 Knowledge versus technique in this book.#