# 11 Vectors

A scalar is a quantity that has magnitude. Scalars include quantities like length, mass, time and speed.

A vector is a quantity that has magnitude and direction. Vectors include quantities like displacement, weight, force and velocity. Vectors may be represented as $\vec{a}$, $\vec{b}$ and $\vec{c}$ or more simply as $\textbf{a, b }$ and $\textbf{c}$.

We will start by looking at vectors in two dimensions.

Vector $\textbf{a}$ has scalar components $a_x$ in the $x$ direction and $a_y$ in the $y$ direction.

Along the $x$-axis there is a vector which is one unit long called $i$ and along the $y$-axis there is a vector which is one unit long called $j$ so we can write $\textbf{a} = a_xi + a_yj$

The magnitude of $\textbf{a}$ can be found by $|a| = \sqrt{a_x^2+a_y^2}$ and the angle between $\textbf{a}$ and the $x$-axis is $cos^{-1}(a_x/|a|)$.

We can add two vectors, $\textbf{a}$ and $\textbf{b}$ by adding their respective components.

$\textbf{a} = a_xi + a_yj$ and $\textbf{b} = b_xi + b_yj$

so $\textbf{a} + \textbf{b} = (a_x + b_x)i + (a_y + b_y)j$

Example 11.2: Given $\textbf{a}=3i+4j$ and $\textbf{b}=2i+6j$ find $\textbf{a}+\textbf{b}$.

 $\textbf{a}$ = $3i+4j$ $\textbf{b}$ = $2i+6j$ $\textbf{a}+\textbf{b}$ = $(3+2)i+(4+6)j$ = $5i+10j$

We can subtract vector $\textbf{b}$ from vector $\textbf{a}$ by subtracting the respective components.

$\textbf{a} = a_xi + a_yj$ and $\textbf{b} = b_xi + b_yj$

so $\textbf{a} - \textbf{b} = (a_x - b_x)i + (a_y - b_y)j$

Example 11.3: Given $\textbf{a}=4i+5j$ and $\textbf{b}=6i+3j$ find $\textbf{a}-\textbf{b}$.

 $\textbf{a}$ = $4i+5j$ $\textbf{b}$ = $6i+3j$ $\textbf{a}-\textbf{b}$ = $(4-6)i+(5-3)j$ = $-2i+2j$

The vector dot product or scalar product multiplies vector $\textbf{a}$ by vector $\textbf{b}$ to give a scalar result.

$\textbf{a}\ . \textbf{b} = a_x . b_x + a_y . b_y$

Another way to calculate the vector dot product is

$\textbf{a}\ . \textbf{b} = |a|\ . |b|\ cos(\theta)$

Example 11.4a: Given $\textbf{a}=2i-3j$ and $\textbf{b}=i+4j$ find $\textbf{a}\ .\textbf{b}$

 $\textbf{a}$ = $2i-3j$ $\textbf{b}$ = $i+4j$ $\textbf{a}\ .\textbf{b}$ = $2\ . 1 + (-3)\ . 4$ = $-10$

Example 11.4b: Given $\textbf{a}=(3, 10^{\circ})$ and $\textbf{b}=(4, 70^{\circ})$ find $\textbf{a}\ .\textbf{b}$

 $\textbf{a}$ = $(3, 10^{\circ})$ $\textbf{b}$ = $(4, 70^{\circ})$ $\textbf{a}\ . \textbf{b}$ = $3\ . 4\ . cos(60)$ = $6$

In addition to the vector dot product there is a vector cross product. The vector cross product of $\textbf{a}$ and $\textbf{b}$ produces a vector that is perpendicular to the plane containing $\textbf{a}$ and $\textbf{b}$. See section 11.9

So far we have been looking at 2D vectors. To extend vectors to three dimensions we need to add an additional axis, the $z$-axis, which is perpendicular to both the $x$ and $y$ axes and, in this document, is pointing out of the page. The $z$-axis has a unit vector $j$ so the 3D vector $\textbf{a}$ may be represented as $\textbf{a} = a_xi + a_yj + a_zk$

Adding 3D vectors is similar to adding 2D vectors. All we have to do is add the components for the $z$ dimension.

$\textbf{a} = a_xi + a_yj + a_zk$ and $\textbf{b} = b_xi + b_yj + b_zk$

so $\textbf{a} + \textbf{b} = (a_x + b_x)i + (a_y + b_y)j + (a_z + b_z)k$

Example 11.6: Given $\textbf{a}=-5i+3j-2k$ and $\textbf{b}=3i+j+4k$ find $\textbf{a}+\textbf{b}$.

 $\textbf{a}$ = $-5i+3j-2k$ $\textbf{b}$ = $3i+j+4k$ $\textbf{a}+\textbf{b}$ = $(-5+3)i+(3+1)j+(-2+4)k$ = $-2i+4j+2k$

We can subtract 3D vector $\textbf{b}$ from 3D vector $\textbf{a}$ by subtracting the respective 3D components.

$\textbf{a} = a_xi + a_yj + a_zk$ and $\textbf{b} = b_xi + b_yj + b_zk$

so $\textbf{a} - \textbf{b} = (a_x - b_x)i + (a_y - b_y)j + (a_z - b_z)k$

Example 11.7: Given $\textbf{a}=-i+3j+4k$ and $\textbf{b}=i-5j+2k$ find $\textbf{a}-\textbf{b}$.

 $\textbf{a}$ = $-i+3j+4k$ $\textbf{b}$ = $i-5j+2k$ $\textbf{a}-\textbf{b}$ = $(-1-1)i+(3-(-5))j+(4-2)k$ = $-2i+8j+2k$

The 3D vector dot product or scalar product multiplies vector $\textbf{a}$ by vector $\textbf{b}$ to give a scalar result.

$\textbf{a}\ . \textbf{b} = a_x\ . b_x + a_y\ . b_y + a_z\ . b_z$

Another way to calculate the vector dot product is

$\textbf{a}\ . \textbf{b} = |a|\ . |b|\ cos(\theta)$

In 3D $|a|= \sqrt{a_x^2 + a_y^2 + a_z^2}$ and $|b|= \sqrt{b_x^2 + b_y^2 + b_z^2}$

Example 11.8a: Given $\textbf{a}=-2i+2j+5k$ and $\textbf{b}=4i+3j+4k$ find $\textbf{a}\ .\textbf{b}$

 $\textbf{a}$ = $-2i+2j+5kj$ $\textbf{b}$ = $4i+3j+4k$ $\textbf{a}\ . \textbf{b}$ = $-2\ . 4 + 2\ . 3 + 5\ . 4$ = $18$

Example 11.8b: Find the angle between the two vectors from Example 11.8a.

 We know $\textbf{a}\ .\textbf{b}$ = $a_x\ . b_x + a_y\ . b_y + a_z\ . b_z$ We also know $\textbf{a}\ .\textbf{b}$ = $|a|\ . |b|\ cos(\theta)$ So we can write $a_x\ . b_x + a_y\ . b_y + a_z\ . b_z$ = $|a|\ . |b|\ cos(\theta)$ rearranging $cos(\theta)$ = $\frac{a_x\ . b_x + a_y\ . b_y + a_z\ . b_z}{|a|\ . |b|}$ which means $\theta$ = $cos^{-1}(\frac{a_x\ . b_x + a_y\ . b_y + a_z\ . b_z$}{|a|\ . |b|}) |a|$=$ \sqrt{a_x^2 + a_y^2 + a_z^2}$=$ \sqrt{2^2 + 2^2 + 5^2}$=$ \sqrt{33}|b|$=$ \sqrt{b_x^2 + b_y^2 + b_z^2}$=$ \sqrt{4^2 + 3^2 + 4^2}$=$ \sqrt{41}\theta$=$ cos^{-1}(\frac{-2\ . 4 + 2\ . 3 + 5\ . 4$}{\sqrt{33}\ . \sqrt{41}})$ = $cos^{-1}(\frac{18}{36.78})$ = $1.06$ rad or $60.70^{\circ}$

The vector cross product is the product of two vectors $a \times b$ that results in a vector. The resultant vector is perpendicular to the plane containing $a$ and $b$ and is in the direction a right hand thread or corkscrew would travel when rotated from $a$ to $b$. This means $a \times b$ is on the same unit vector as $b \times a$ but points in the opposite direction.

There are two ways to calculate the vector cross product:

• $a \times b = |a|\ |b|\ sin(\theta) . n$
where $\theta$ is the angle between $a$ and $b$ and $n$ is the right handed unit vector perpendicular to $a$ and $b$ and pointing in the direction of a right hand thread or corkscrew rotating from $a$ to $b$.

• $a \times b = \begin{vmatrix} i & j & k \\ a_x & a_y & a_z \\ b_x & b_y & b_z \notag \end{vmatrix}$

Expanding the determinant we get

$a \times b = (a_y b_z - a_z b_y)i - (a_x b_z - a_z b_x)j + (a_x b_y - a_y b_x)k$

Note: Remember the signs rule for expanding determinants which changes the sign of the $j$ term.

An alternative way to specify a vector is give its magnitude and the angle it makes with each of the axes. The three angles are usually called $\alpha, \beta$ and $\gamma$ where $\alpha$ is the angle between the vector and the $x$-axis, $\beta$ is the angle between the vector and the $y$-axis and $\gamma$ is the angle between the vector and the $z$-axis.

The magnitude of vector $a$ is given by $|a| = \sqrt{a_x^2+a_y^2+a_z^2}$ so
$cos \alpha = a_x/|a|$, $cos \beta = a_y/|a|$ and $cos \gamma = a_z/|a|$,

Bee waggle dance    Vector Search

# 12 Series

Imagine you are given this set of numbers: $-7, -4, -1, 2, 5$ you can probably see what the next number will be. You can see there is a relationship between a number and the next. We call this set of numbers a series or a progression. If we subtract any number, after the first, from the previous number we can see there is a common difference of 3 which means we can define this series by the first number $a=-7$ and the common difference $d=3$. Numbers in a series are called terms.

The above progression has $a=-7$ and $d=3$. Given one term we can evaluate the next by adding the common difference $d$. We call this an arithmetic progression. The first term is $a = -7$, the second is $a+d=-4$, the third is $a+2d=-1$ and the $n^{th}$ term is $a+(n-1)d$.

When the young Leonard Euler was in primary school in the early 18th century his teacher asked the class to add the numbers $1$ to $100$. Euler immediately walked up to the teacher with the answer written on a piece of paper.

Euler had noticed that $1+100=101$, $2+99=101$, $3+98=101$ so the sum of numbers $1$ to $100 = 100 \times 101 \div 2=5050$.

More generally the sum to $n$ terms of an arithmetic progression with a first term $a$ and a common difference $d$ is given by
$\sum_{k=0}^{k=n-1} (a+kd) = \frac{n}{2}(2a+(n-1)d)$

Example 12.1: Find the sum to 10 terms of the following series:
$3, 7, 11, 15, 19 . . .$

We can see the first term $a=3$ and the common difference $d=4$

\begin{align} \sum_{k=0}^{k=9} (3+4k) & = \frac{10}{2}(2 \times 3+9 \times 4) \\\\ & = 5(6+36) \\\\ & = 210 \end{align}

What is the next term in this series: $3, 6, 12, 24, 48 . . .$? In this series there is no common difference but there is a common ratio. If we divide each term by the previous term the ratios are all the same. This series, then, is a geometric progression. The first term is $a = 3$ and the common ratio is $r = 2$.

The $n^{th}$ term is given by $a r^{n-1}$

The sum to $n$ terms of a geometric progression can be written as

$\sum_{k=0}^{k=n-1} (ar^k) = a + ar + ar^1 + . . . + ar^{n-1}$

Multiplying both sides by $r$ we get

$r\sum_{k=0}^{k=n-1} (ar^k) = ar + ar^1 + ar^2 + . . . + ar^n$

Subtracting the second equation from the first we get

$(1-r)\sum_{k=0}^{k=n-1} (ar^k) = a - ar^n$

So we can write

$\sum_{k=0}^{k=n-1} (ar^k) = a\frac{1-r^n}{1-r} = a\frac{r^n-1}{r-1}$

Example 12.2: Find the sum to 10 terms of the following series:
$3, 6, 12, 24, 48 . . .$

The first term $a=3$ and the common ratio is $r=2$

\begin{align} \sum_{k=0}^{k=9} (3 \times 2^k) & = 3 \frac{1-2^{10}}{1-2} \\\\ & = 3 \frac{1-1024}{1-2} \\\\ & = 3069 \end{align}

A factorial number is a natural number multiplied by each smaller natural number down to 1. Factorial numbers are written with a trailing $!$. For example, $6! = 6 \times 5 \times 4 \times 3 \times 2 \times 1 = 720$.

$0!$ is defined to be $1$ and a number like $-9!$ is $-(9!)$ because factorials are natural numbers not integers.

Example 12.3: Evaluate the following factorials $3!, 6!, 9!, -4!, 0!$

$3!=3 \times 2 \times 1 = 6$

$6! = 720$

$9!=362880$

$-4!=-(4!)=-24$

$0!=1$

The binomial theorem allows us to expand expressions like $(a+b)^n$ without sequentially expanding each bracket. The binomial theorem states:

\begin{align} (a+b)^n = \sum_{r=0}^{n} n^c_r a^{n-r} b^r \end{align}

where $n^c_r = \frac{n!}{r!(n-r)!}$

Example 12.4: Expand the following expressions $(a+b)^2, (x+a)^3 (x+y)^6$

 $(a+b)^2$ = $n^2_0 a^2 + n^2_1 ab + n^2_2 b^2$ = $a^2+2ab+b^2$ $(x+a)^3$ = $n^3_0 x^3 + n^3_1 x^2 a + n^3_2 xa^2 + n^3_3 a^3$ = $x^3+3x^2a+3xa^2+a^2$ $(x+y)^6$ = $n^6_0 x^6 + n^6_1 x^5 y + n^6_2 x^4 y^2 + n^6_3 x^3 y^3$ $\ +\ n^6_4 x^2 y^4 + n^6_5 x y^5 + n^6_6 y^6$ = $x^6 + 6 x^5 y + 15 x^4 y^2 + 20 x^3 y^3$ $\ +\ 15 x^2 y^4 + 6 x y^5 + y^6$

# 13 Sets

A set is a collection of things. In set theory the things in a set are called elements. Elements can be real like bananas, cars or mountains. Elements can be virtual like integers, websites, ideas or even other sets.

Sets can be finite or infinite. Finite sets could be the wheels on a car, the people on the Earth, the atoms in a molecule or the stars in the universe. Infinite sets could be all natural numbers or all prime numbers.

The Universal set, U, is the set of all the elements in a particular domain. The Null set is a set with no elements.

Sets are normally given a capital letter and the elements are enclosed in curly brackets. We could write:

$A = \{2, 4, 6, 8\}$

$A$ is a set consisting of the objects $2, 4, 6$ and $8$.

$B = \{2, 3, 5, 7\}$

$B$ is a set containing the objects $2, 3, 5$ and $7$.

$C = \{red, green, blue\}$

$C$ is a set consisting of the colours $red, green$ and $blue$.

Sometimes there are a lot of elements in a set and it can be easier to give rules that specify the elements rather than give the elements themselves. For example we could write

$A = \{n |\ n\ is\ even\ and\ 1 < n < 9\}$

$B = \{p |\ p\ is\ prime\ and\ p < 10\}$

$C = \{c |\ c\ is\ a\ primary\ colour\ on\ a\ computer\ monitor\}$

The | character may be read as given that or subject to. The statement on the right of the | character is called a predicate.

Sets $A, B$ and $C$ in this list are identical to $A, B$ and $C$ in the first list. There is no unique way to write a set. You can write anything in a predicate as long as it uniquely defines the set though, following Einstein's maxim, it should be as simple as possible but no simpler.

Elements can only be in sets once. There are no negative elements and there is no concept of the order of the elements so

{1, 3, 5, 7, 9} = {9, 7, 5, 3, 1} = {1, 9, 7, 3, 5}

The symbol $\in$ means is an element of, is a member of or exists in so we can write $4 \in A$, $3 \in B$ or $red \in C$ using the sets above.

Example 13.1 List the elements in the following sets.

$A = \{0, 1 \}$

$B = \{n \in N | n < 2 \}$ where $N$ is the set of natural numbers

$C = \{x \in R | x^2 - x = 0 \}$ where $R$ is the set of real numbers

Leonard Euler used to draw a closed curve around a set to distinguish what was in a set from what was not in a set. The curve can be any shape as long as it seperates what is in the set from what isn't.

John Venn extended Euler’s diagrams to illustrate the way different sets interact. Looking at $A$ and $B$ we see they share an element so if they were on the same diagram we could draw it like this.

Figure 13.2 has eight regions:

 1 Elements in $A$ $\{2,\ 4,\ 6,\ 8\}$ 2 Elements in $B$ $\{2,\ 3,\ 5,\ 7\}$ 3 Elements in $A$ that are also in $B$ $\{2\}$ 4 Elements in $A$ and elements in $B$ $\{2,\ 3,\ 4,\ 5,\ 6,\ 7,\ 8\}$ 5 Elements not in $A$ $\{3,\ 5,\ 7\}$ 6 Elements not in $B$ $\{4,\ 6,\ 8\}$ 7 Elements not in $A \cap B$ $\{\ \}$ 8 Elements not in $A \cup B$ $\{3,\ 4,\ 5,\ 6,\ 7,\ 8\}$

Line 1 is set $A$, line 2 is set $B$ so we can write:

$A = \{2, 4, 6, 8\},\ B = \{2, 3, 5, 7\}$

Line 3 (elements in $A$ that are also in $B$) is called the intersection of $A$ and $B$ and has the symbol $\cap$. So we can write:

$A \cap B = \{2\}$

Line 4 (elements in A and elements in B) is called the union of A and B. It has the symbol $\cup$ which means we can write:

$A \cup B = \{2, 3, 4, 5, 6, 7, 8\}$

Line 5 (elements not in $A$) is called the complement of $A$. The complement may be shown as $A'$ or $A^{-1}$ or $A^T$ or $not A$. We can write:

$A' = A^{-1} = A^T = not A\ = \{3, 5, 7\}$

Line 6 (elements not in $B$) is the complement of $B$. We can write:

$B' = B^{-1} = B^T = not A = \{4, 6, 8\}$

Line 7 is a set with no elements. Sets with no elements are called Null sets. We can write:

$(A \cup B)' = \{\}$

Line 8 is the set of elements not in $A \cap B$. We can write:

$(A \cap B)' = \{3, 4, 5, 6, 7, 8 \}$

The blue rectangle in figure 13.2 is the set that contains all the above sets. It is called the universal set.

Example 13.2 Given $A = \{a, b, c, d, e, f\}$, $B = \{a, c, d, f, h\}$ and $C = \{e, f, x, y\}$:

a.  Draw a Venn diagram of the given data

b.  $A \cup B$

c.  $A \cap B$

d.  $A \cap (B \cup C)$

e.  $B \cup (A \cap C)$

$B$ is a subset of $A$ if all the elements of $B$ are also in $A$. This can be written as:

$B \subseteq A$ - $B$ is a subset of $A$

This expression allows for the possibility that every element in $A$ is also in $B$, that is $A = B$. When there are elements in $A$ that are not in $B$, that is $A \neq B$, and all the elements in $B$ are in $A$ then $B$ is called a proper subset of $A$ and this is written $B \subset A$.

Supersets are sets that contain other sets as well as other elements. So if $B$ is a subset of $A$ then $A$ is a superset of $B$. The statement is true if $A \neq B$. The statement is still true if $A = B$.

The null set is a subset of all sets.

Example 13.3 Given $S = \{a, b, c, d, e\}$:

a.  How many subsets are there in $S$?

b.  How many proper subsets are there in $S$?

c.  Why is there a difference between the number of subsets and the number of proper subsets of $S$?

The Power set, $P(D)$, is the set of all possible subsets. If $D = \{2, 4, 6\}$ then

$P(D) = \{\{2\}, \{4\}, \{6\}, \{2, 4\}, \{2, 6\}, \{4, 6\}, \{2, 4, 6\}, \{\}\}$

If there are $n$ elements in $A$ then the power set contains $2^n$ subsets.

The cardinality of a set is the number of elements in the set. Cardinality is shown by the $|\ |$ symbols. For the sets $A, B, C$ and $D$ from above we get $|A| = 4$, $|B| = 4$, $|C| = 3$ and $|D| = 3$. Notice that $|P(D)| = 8$.

A set with a cardinality of $n$ has a power set with a cardinality of $2^n$.

The difference between two sets, $A – B$, sometimes written as $A \setminus B$, is defined to be the elements of $A$ except for any elements that also appear in $B$.

Given $A = \{2, 4, 6, 8 \}$ and $B = \{ 2, 3, 5, 7\}$ then $A – B = A \setminus B = \{4, 6, 8\}$. $2$ is removed from $A$ because it is also in $B$ but you cannot remove $3, 5$ or $7$ from $A$ because they were not in $A$.

More generally

$A – B = \{x\ |\ x\ \in\ A\ and\ x\ \notin B\}$

The symmetric difference of two sets is most easily thought of as the difference of the union and the intersection. So we can write:

$A \triangle B = \{A \cup B\} – \{A \cap B\}$

The Cartesian product of two sets is the set of all the products of pairs of elements of the two sets. Given $C = \{red, green, blue\}$ and $D = \{2, 4, 6\}$, the Cartesian product is given by:

 $C × D =$ $\{\{red,2\}, \{red, 4\},\{ red, 6\}$, $\ \ \{green, 2\},\{ green, 4\},\{ green, 6\}$, $\ \ \{blue, 2\},\{ blue, 4\},\{ blue, 6\}\}$

Example 13.4 Given $A = \{2, 3, 5, 7, 11\}$ and $B = \{a, b, c, d, e\}$:

a.  Give the power set of $A$

b.  What is the cardinality of $B$?

c.  List all the elements in $A \times B$

# 14 Probability

The probability of an event happening is defined to be the number of ways in which the event can happen divided by the total number of possible outcomes. For example, if a fair coin can never land on it's edge then the total number of possible outcomes is two, heads or tails. The number of ways in which you can get a head is one and the number of ways in which you can get a tail is one. Therefore, the probability of getting a head, $P(head)$, is $1/2$, which is the same as the probability of getting a tail.

Probabilities are given as a fraction or decimal number between $0$ and $1$. $0 \leq P(event) \leq 1$. $0$ means the event will not happen, $1$ means the event will happen. Everything between means the event may happen. Probabilities may also be expressed as percentages.

$P(head) = P(tail) = 1/2$ or $0.5$ or $50\%$

Independent events are events that are not effected by other events. If you have a bag with 50 red balls and 50 blue balls that are all identical except for the colour then the probability of selecting a red ball is determined by the number of red and blue balls and nothing else.

Dependent events are events that can be effected by previous events. If you had taken a ball out of the bag and not replaced it then the probability of selecting a red ball has been changed by the first event.

Mutally exclusive events are events such that if one happens then the other cannot happen. If you toss a coin you will get heads or tails. If you get heads you cannot get tails. If you get tails you cannot get heads. The two outcomes are mutually exclusive.

Imagine an experiment that involves tossing a coin 10 times. You could get 10 heads, you could get 10 tails but the most likely outcome is 5 heads and 5 tails. Imagine we got $n$ heads where $0 \leq n \leq 10$ then the probability of heads or tails is:
$P($ heads $or$ tails $)=P($ heads $)+P($ tails $)$.

In the previous example the events were mutually exclusive so there was no overlap of the regions in the Venn diagram. Imagine we are investigating possible link between flying and deep vein thromboses. Some people fly, some don't. Some get deep vein thromboses, some don't. Some people fly and get deep vein thromboses. We can show this on a Venn diagram.

If we add $P($ Fly $)$ and $P($ DVT $)$ we will include the overlap, that is $P($ Fly $\cap$ DVT $)$, twice so the probability of a person flying or getting a deep vein thrombosis is given by:
$P(A\ or\ B) = P(A \cup B) = P(A) + P(B) - P(A \cap B)$.

In our experiment into flying and deep vein thromboses we are likely to be interersted in the set of people who fly and get deep vein thromboses, that is the region of intersection of the two sets. This group is given by:
$P(A\ and\ B) = P(A) \times P(B) = P(A \cap B)$.

## Summary

$P(A\ or\ B) = P(A) + P(B) - P(A \cap B)$

$P(A\ and\ B) = P(A) \times P(B) = P(A \cap B)$

Note: When $A$ and $B$ are mutually exclusive $P(A \cap B)=0$

Tree diagrams can be used to identify all the different possible outcomes. Imagine you want to know all the possible outcomes from tossing a fair coin three times. The tree diagram would look like this:

The chances of getting 3 heads is
$P(3\ heads) = 1/2 \times 1/2 \times 1/2 = 1/8$.

There are three ways in which you could get 2 heads so the probability of getting two heads is
$P(2\ heads) = 3(1/2 \times 1/2 \times 1/2) = 3/8$.

There are three ways in which you could get 1 head so the probability of getting one head is
$P(1\ head) = 3(1/2 \times 1/2 \times 1/2) = 3/8$.

There is one way in which you could get no heads. The probability of getting no heads is
$P(0\ head) = (1/2 \times 1/2 \times 1/2) = 1/8$.

Notice:
1. the numerators of $P(3)$, $P(2)$, $P(1)$ and $P(0)$ are the same as the 4th row of Pascal's triangle.
2. $P(3) + P(2) + P(1) + P(0) = 1$

There is one way in which you could get no heads so the probability of getting at least one head is $P(at\ least\ 1\ head) = 1 - (1/2 \times 1/2 \times 1/2) = 7/8$.

Conditional probability is the probability of event $A$ happening given that event $B$ has happened. We write the probability like this $P(A|B)$ where the | should be read as 'given that'. $P(A|B)$ would read as the probability of $A$ happening given that $B$ has happened.

Q: The table shows the numbers of men and women that voted in the 2016 American presidential election. If you select a voter at randon what is the most likely way they voted?

 Women Men Clinton 34.4 25.4 Trump 26.8 32.8 Other 2.5 3.7

A: Of the 125.6 million people that voted 59.8 million voted for Clinton and 59.5 million voted for Trump.

$P(Clinton)=59.8/125.6=0.476\ or\ 47.6\%$.

$P(Trump)=59.6/125.6=0.474\ or\ 47.5\%$.

so the most likely way they voted is for Clinton

Q: If your selection was male what is the most likely way they voted?

A: Of the 61.8 million men that voted 25.4 million voted for Clinton and 32.8 million voted for Trump.

$P(Clinton|male)=25.4/61.8=0.410\ or\ 41\%$.

$P(Trump|male)=32.8/61.8=0.530\ or\ 53\%$.

so the most likely way they voted is for Trump

# 15 Regression

When you analyse experimental data you will want to see whether there is any relation between the sets of data. One way to do this is to calculate the Pearson product-moment correlation coefficient.

Karl Pearson devised a coefficient to measure the correlation between two sets of data. The coefficient ranges from $-1$ to $1$. A value of $1$ means there is perfect correlation between the data sets, a value of $0$ means there is no correlation and a value of $-1$ means there is perfect negative correlation between the data sets. Note: independent data may be strongly correlated, correlation does not mean causality.

Assume you have a set of independent data $x$ with corresponding dependent data $y$ then Pearson's product-moment correlation coefficient is given by:

$r=\frac{n \sum xy- \sum x \sum y}{\sqrt{n\sum x^2-(\sum x)^2} \times \sqrt{n\sum y^2-(\sum y)^2}}$

where $n$ is the number of samples and $\sum$ means the sum of the values in the set of data

If the value of $|r| \lt 0.5$ then the correlation is weak or non-existent. If the value of $|r| \geq 0.5$ then there is a correlation between the two sets of data.

If $|r| \geq 0.5$ then you will want to find the gradient and y-intercept of the regression line. To do this we will use the method of least squares. Least squares minimises the square of the perpendicular distance between each data point and the regression line. The square of the distance is used because points below the line give a negative distance and we want to minimise to sum of all the separate distances. The gradient and y-intercept are given by:

$m = \frac{n \sum xy- \sum x \sum y}{n\sum x^2-(\sum x)^2}$

$c = \frac{\sum x^2 \sum y- \sum x \sum xy}{n\sum x^2-(\sum x)^2}$

Example 15.1: Given the following data calculate the Pearson correlation coefficient.

 $x$ 0 1 2 3 4 $y$ 8 14 13 20 19

To find $r$ we need $\sum x$, $\sum y$, $\sum xy$, $\sum x^2$, $\sum y^2$ and $n$.

 $x$ 0 1 2 3 4 10 $y$ 8 14 13 20 19 74 $xy$ 0 14 26 60 76 176 $x^2$ 0 1 4 9 16 30 $y^2$ 64 196 169 400 361 1190

Putting these values into Pearson's equation

$r=\frac{n \sum xy- \sum x \sum y}{\sqrt{n\sum x^2-(\sum x)^2} \times \sqrt{n\sum y^2-(\sum y)^2}}$

$=\frac{5 \times 176 - 10 \times 74}{\sqrt{5 \times 30 - 10^2} \times \sqrt{5 \times 1190 - 74^2}}$

$=0.909$

A value for $r=0.909$ means there is a high correlation for these data which means it is worth calculating the gradient and y-intercept of the correlation line.

$m=\frac{n \sum xy- \sum x \sum y}{\sqrt{n\sum x^2-(\sum x)^2} \times \sqrt{n\sum y^2-(\sum y)^2}}$

$=\frac{5 \times 176 - 10 \times 74}{5 \times 30 - 10^2}$

$=2.80$

$c=\frac{ \sum x^2 \times \sum y - \sum x \sum xy}{n\sum x^2-(\sum x)^2}$

$=\frac{30 \times 74 - 10 \times 176}{\sqrt{5 \times 30 - 10^2} \times \sqrt{5 \times 1190 - 74^2}}$

$=9.2$

Here is a plot of the data and the regression line

# 16 Complex Numbers

A square root of a number is a value which, when multiplied by itself, gives you the original number. So a square root of $4$ is $2$ because $2 \times 2 = 4$. Another square root of $4$ is $-2$ because $(-2) \times (-2) = 4$.

So what are the square roots of $-4$? They can't be $2$ or $-2$ because these are the roots of $4$. We could let $-4 = -1 \times 4$ now we only need to deal with the square root of $-1$.

We are going to define $\sqrt{-1}=i$ (or $j$ if you are an electronic engineer). $i$ does not have a value, you cannot calculate it, it is simply a number in a different dimension, called, sadly, an imaginary number. It does, however, mean we can now find the square roots of $-4$. They are $+2i$ and $-2i$.

We can multiply $i$ by a scalar to get $2i$, $5i$, $-6i$, $ai$ and so on. These are all imaginary numbers. We can add imaginary numbers to real numbers to get complex numbers like $5+3i$, $2-3i$ and, more generally, $a+ib$.

You can imagine real numbers on a number line. For complex numbers we add a second, perpendicular axis which is called the imaginary axis. Real numbers are one dimensional quantities. Complex numbers are two dimensional quantities.

## 16.1 Cartesian Form of Complex Numbers

A complex number written in the Cartesian form is given as $z = a + ib$.

It is called the Cartesian form because $a$ is the $x$ value and $b$ is the $y$ value as shown in figure 16.1.

## 16.2 Polar Form of Complex Numbers

The complex number $a + ib$ can be also be given as a radius and an angle. Look at figure 16.2. The magnitude of the complex number, called the modulus, is given by

$$|z| = r = \sqrt{a^2 + b^2}$$

The angle, called the argument, is given by $$arg(z) = \theta = tan^{-1}(\frac{b}{a})$$

The polar form of complex numbers can be written with any of the following notations:

$$z = r(cos \theta + isin \theta) = rcis( \theta) = r \angle \theta = [r, \theta ]$$

Baseline tutorials use $[r, \theta ]$ notation for answers in polar form.

## 16.3 Addition and Subtraction of Complex Numbers

The sum of two complex numbers is equal to the sum of the real parts and the sum of the imaginary parts, rather like vectors.

If $z_1=2+5i$ and $z_2=4+2i$ then

$$z_1+z_2=(2+4)+(5+2)i=6+7i$$

The difference of two complex numbers is equal to the difference of the real parts and the difference of the imaginary parts. Using $z_1$ and $z_2$ from above we get

$$z_1-z_2=(2-4)+(5-2)i=-2+3i$$

## 16.4 Product of Complex Numbers

The product of two complex numbers can be found by multiplying the parts of one number by the parts of the other. Using $z_1$ and $z_2$ from above we get:

 $z_1 \times z_2$ $=$ $(2+5i)(4+2i)$ $=$ $2 \times 4 + 2 \times 2i + 5i \times 4 + 5i \times 2i$ $=$ $8 + 4i + 20i + 10i^2$ Remember that $i=\sqrt{-1}$ so $i^2=-1$ so $z_1 \times z_2$ $=$ $8 + 24i - 10$ $=$ $-2 + 24i$

Another, and easier, way to find the product of two complex numbers is to put the numbers in polar form. Imagine we have $z_1 = r_1(cos \theta + isin \theta)$ and $z_2 = r_2(cos \phi + isin \phi)$ then

$$z_1 z_2 = r_1 r_2(cos(\theta + \phi) + isin( \theta + \phi))$$

or $$z_1 z_2 = r_1 r_2 \angle (\theta + \phi)$$

## 16.5 The Complex Conjugate

You probably already know the identity

$(a+b)(a-b)=a^2-b^2$

With a small change we can write

$(a+ib)(a-ib)=a^2-(ib)^2$.

We also know $i = \sqrt{-1}$ so $i^2 = -1$ which means

$(a+ib)(a-ib)=a^2+b^2$.

The complex conjugate is the quantity that creates a real number from a complex number. If $z=a+ib$ then the complex conjugate is $z^*=a-ib$ and if $z=a-ib$ then the complex conjugate is $z^*=a+ib$. Multiplying a complex number by it's conjugate always produces a real number.

## 16.6 Quotient of Complex Numbers

To find the quotient of two Cartesian form complex numbers $z_1/z_2$ start by multiplying the numerator and denominator by the complex conjugate of the denominator. Using $z_1$ and $z_2$ from above we get:

 $\large{\frac{z_1}{z_2}}$ $=$ $\frac{2+5i}{4+2i}$ $=$ $\frac{(2+5i)(4-2i)}{(4+2i)(4-2i)}$ $=$ $\frac{8+10-4i+20i}{16+4}$ $=$ $\frac{18+16i}{20}$ $=$ $\frac{9+8i}{10}$

In section 16.4 we noted that the product of two complex numbers can be easily calcualted using the polar form. The same is true for the quotient. Using $z_1 = r_1(cos \theta + isin \theta)$ and $z_2 = r_2(cos \phi + isin \phi)$ we get

$$z_1 / z_2 = (r_1 / r_2)(cos(\theta - \phi) + isin( \theta - \phi))$$

or $$z_1 / z_2 = (r_1 / r_2) \angle (\theta - \phi)$$

Note: In general terms it is easier to use the Cartesian form of complex numbers for addition and subtraction and the polar form for multiplication and division

## 16.7 Euler's Formula for Complex Numbers

We have already seen expressions of the form $cos \theta + sin \theta$. We can turn this into a complex expression by adding an $i$ like this $z = cos \theta + i sin \theta$ (often abreviated to $cis \theta$).

The MacLaurin expansion for $cos \theta$ is:

$$cos \theta = \sum_{n=0}^{\infty} 1 - \frac{x^2}{2!} + \frac{x^4}{4!} . . .$$

For $sin \theta$ it is:

$$sin \theta = \sum_{n=0}^{\infty} x - \frac{x^3}{3!} + \frac{x^5}{5!} . . .$$

And for $e^z$ it is:

$$e^z = \sum_{n=0}^{\infty} 1 + z + \frac{z^2}{2!} + \frac{z^3}{3!} + \frac{z^4}{4!} + \frac{z^5}{5!} . . .$$

Now, if we let $z=i \theta$ then $e^z$ becomes:

$$e^{i \theta} = \sum_{n=0}^{\infty} 1 + i \theta - \frac{ \theta^2}{2!} - \frac{i \theta^3}{3!} + \frac{ \theta^4}{4!} + \frac{i \theta^5}{5!}. . .$$

Next we group the odd and even terms:

$$e^{i \theta} = \sum_{n=0}^{\infty} (1 - \frac{ \theta^2}{2!} + \frac{ \theta^4}{4!} . . .) + i( \theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!}. . . )$$

Which can be rewritten as:

$e^{i \theta} = cos \theta + i\ sin \theta$

This simple formula was first derived by Euler1. It simplifies the solution to an immense range of problems2 in science and engineering including control theory, improper integrals, fluid dynamics, dynamic equations, electromagnetism and electrical engineering, signal analysis, quantum mechanics, relativity, geometry, fractals, algebraic and analytic number theory.

A special case of the formula is when $\theta = \pi$. $cos \pi=-1$ and $sin \pi = 0$ so we can write:

$e^{i \pi} + 1 = 0$

This subtle formula links five fundamental quantities, $e, i, \pi, 1$ and $0$.

## 16.8 De Moivre's Formula

De Moivre's3 formula states:

$(cos(\theta) + i\ sin(\theta))^n = cos(n \theta) + i\ sin(n \theta)$

De Moivre proved his formula before Euler published $e^{i \theta} = cos \theta + i\ sin \theta$ but Euler's formula makes proving De Moivre's formula easy.

 We know $e^{i \theta}$ $=$ $cos(\theta) + i\ sin(\theta)$ and $(e^{i \theta})^n$ $=$ $e^{i n \theta}$ so it's a fairly easy step to see $(cos(\theta) + i\ sin(\theta))^n$ $=$ $cos(n \theta) + i\ sin(n \theta)$

## 16.9 Roots of Polynomial Equations

A polynomial equation of order $n$ has $n$ roots. If one of the roots is the complex number $z$ then another root will be $z^*$, the complex conjugate of $z$.

Example 16.1: Find the roots $2x^3+5x^2-2x-15$ given one of the roots is $x+2+i$.

The given root is $x+2+i$ so we know there is another root $x+2-i$. Multiply these together:

 $(x+2+i)(x+2-i)$ $=$ $x^2+2x-ix$  $+2x+4-2i$    $+ix+2i-i^2$ = $x^2+4x+5$

Now we divide $2x^3+5x^2-2x-15$ by $x^2+4x+5$ to get $2x - 3$

So the roots of $2x^3+5x^2-2x-15$ are $x^2+4x+5$, $x^2+4x-5$ and $2x - 3$

Example 16.2: Find the cube roots of $-8$.

There are three cube roots of $-8$. Remembering $cos \pi = -1$ and $sin \pi = 0$ we can write

 $-8$ $=$ $8(cos \pi + i sin \pi)$

If we add $2 \pi$ to $cos \pi$ or $sin \pi$ we move forward one wavelength and get the same value so we can write

 $-8$ $=$ $8(cos((2n + 1)\pi) + i sin((2n + 1)\pi))$ $=$ $8e^{i (2n + 1)\pi}$ So $\sqrt[3]{-8}$ = $(8e^{i (2n + 1)\pi})^{1/3}$ $=$ $2e^{i (2n + 1)\pi /3}$ $=$ $2(cos((2n + 1) \pi/3) + i sin((2n + 1) \pi/3))$

For values of $n = 0$, $1$ and $2$ we get:
$root_0 = 1 + 1.71i$, $root_1 = -2$ and $root_2 = 1 - 1.71i$

We can see what this means on the diagram below

# 17 Differentiation

Imagine you are Galileo's assistant. You have gone to the leaning tower of Pisa to test whether objects with different masses fall at different speeds. As you release an object you start a timer so that at $t = 0$ the downward velocity is also zero.

You know from Newton's equations (though Newton hadn't written them at this point) that $s=ut+\frac{1}{2}at^2$. We know $u=0$ and that $a$ is the acceleration due to gravity so we can write $s=\frac{1}{2}gt^2$.
Note: We are measuring downwards from the release point.

Newton's first equation of motion states $v=u+at$ so we can write $v=gt$. The acceleration due to gravity $g$ is constant over these distances so the velocity is proportional to the time. Time $t$ is the independent variable and distance $s$ is the dependent variable.

$s=\frac{1}{2}gt^2$

$v=gt$

We can be pretty sure that distance and velocity are related. The question is how? Start with $s=\frac{1}{2}gt^2$. To convert $s=\frac{1}{2}gt^2$ into $gt$ we need multiply the expression by the exponent of $t$ and then reduce the exponent by $1$.

The process has given us the rate of change of distance with respect to time, $s$ with respect to $t$, which is the velocity. If we repeat the process we get the rate of change of velocity with respect to time, $v$ with respect to $t$, which is $g$ the acceleration.

Velocity is the rate of change of position. Acceleration is the rate of change of velocity.

The process is called differentiation. In this case it has given us velocity and acceleration. In general though it gives us the rate of change of one variable with respect to another.

## 17.1 Polynomials

If $y=ax^n + bx^{n-1} + cx^{n-2} . . .$ then $\frac{dy}{dx} = nax^{n-1} + (n - 1)bx^{n-2} + (n - 2)cx^{n-3} . . .$

 Example 17.1 Given $y=2x^3 + 4x^2 + 3x + 5$ find $dy / dx$ $y$ $=$ $2x^3 + 4x^2 + 3x + 5$ $\frac{dy}{dx}$ $=$ $3.2x^2 + 2.4x + 3 + 0$ $=$ $6x^2 + 8x + 3$

## 17.2 Chain Rule

If $y=y(u)$ and $u=u(x)$ then $\frac{dy}{dx} = \frac{dy}{du} \frac{du}{dx}$

 Example 17.2 Given $y=(2x^3+4x^2)^4$ find $dy / dx$. Let $u=2x^3+4x^2$ so $y=u^4$ then $\frac{dy}{du}=4u^3$ and $\frac{du}{dx}=6x^2+8x$ $\frac{dy}{du}\frac{du}{dx}$ $=$ $4u^3 (6x^2 + 8x)$ $=$ $4(2x^3+4x^2)^3 (6x^2 + 8x)$ Sanity Check: As a quick sanity check look at the $x^3$ term in the question. If we expanded the bracket the highest order term would be $16x^{12}$. When we differentiate this term we would get $192x^{11}$.If we expand the highest order term in our answer we get $4. 8x^9 . 6x^2 = 192x^{11}$ so we can have some confidence our answer is correct.

 Example 17.3 Differentiate $y=sin(3x)$. Let $u=3x$ then $\frac{du}{dx}=3$ and $y=sin(u)$ then $\frac{dy}{du}=cos(u)$ so $\frac{dy}{dx}=\frac{dy}{du} \frac{du}{dx} = cos(u) . 3 = 3cos(3x)$ More generally $\frac{d}{dx} sin(ax) = acos(ax)$ Similarly $\frac{d}{dx} cos(ax) = -asin(ax)$ and $\frac{d}{dx} tan(ax) = a sec^2 (ax)$

## 17.3 Product Rule

If $u=u(x)$ and $v=v(x)$ then $\frac{d}{dx}(uv) = u \frac{dv}{dx} + v \frac{du}{dx}$

 Example 17.4 Differentiate $y=3x^3 e^x$ Let $u=3x^3$ and $v=e^x$ then $\frac{du}{dx}=9x^2$ and $\frac{dv}{dx}=e^x$ $\frac{dy}{dx}$ $=$ $u\frac{dv}{dx} + v \frac{du}{dx}$ $=$ $3x^3.e^x + e^x.9x^2$ $=$ $3x^2.e^x(x + 3)$

 Example 17.5 Differentiate $y=3x^2 cos(4x)$ Let $u=3x^2$ and $v=cos(4x)$ then $\frac{du}{dx}=6x$ and $\frac{dv}{dx}=-4sin(4x)$ $\frac{dy}{dx}$ $=$ $u\frac{dv}{dx} + v \frac{du}{dx}$ $=$ $3x^2(-4sin(4x)) + cos(4x) 6x$ $=$ $3x(2cos(4x)-4xsin(4x))$

## 17.4 Quotient Rule

If $u=u(x)$ and $v=v(x)$ then $\frac{d}{dx}(\frac{u}{v}) = \frac{v \frac{du}{dx} - u \frac{dv}{dx}}{v^2}$

 Example 17.6 Differentiate $y = tan(x)$ Let $u=sin(x)$ and $v=cos(x)$ then $\frac{du}{dx}=cos(x)$ and $\frac{dv}{dx}=-sin(x)$ $\frac{d}{dx}(\frac{u}{v})$ $=$ $\frac{v \frac{du}{dx} - u \frac{dv}{dx}}{v^2}$ $=$ $\frac{cos(x).cos(x) - sin(x)(-sin(x))}{cos^2 (x)}$ $=$ $\frac{cos^2(x) + sin^2(x)}{cos^2 (x)}$ Remember $sin^2(x) + cos^2(x) = 1$ $=$ $\frac{1}{cos^2 (x)} = sec^2 (x)$

 Example 17.7 Given $y = \frac{4-3x}{2x-3}$ find $dy / dx$ Let $u=4-3x$ and $v=2x-3$ So $\frac{du}{dx}=-3$ and $\frac{dv}{dx}=2$ $\frac{d}{dx}(\frac{u}{v})$ $=$ $\frac{v \frac{du}{dx} - u \frac{dv}{dx}}{v^2}$ $=$ $\frac{(2x-3)(-3) - (4-3x)2}{(2x-3)^2}$ $=$ $\frac{-6x + 9 - 8 + 6x}{(2x-3)^2}$ $=$ $\frac{1}{(2x-3)^2}$

## 17.5 Table of Common Standard Differentials

In the following table the left hand column contains functions of $x$ ($y=f(x)$). The right hand column contains the differentials of the functions with respect to $x$ ($dy/dx=f'(x)$).

$y=f(x)$    $dy/dx = f'(x)$
$x^n$$nx^{n-1} sin(ax)$$acos(ax)$
$cos(ax)$$-asin(ax) tan(ax)$$asec^2(ax)$
$e^{ax}$$ae^{ax} ln(ax)$$1/x$

# 18 Integration

At one level integration may be seen as the inverse process of differentiation. We would write:

$I = \int f'(x) dx = F(x) + C$

The $+C$ is called the constant of integration. If you differentiate a constant you get zero. If you integrate an expression there may have been a constant so we add $+C$ just in case.

In the following table the left hand column contains functions of $x$ ($y=f(x)$). The right hand column contains the integrals of the functions with respect to $x$ ($\int f(x) dx=F(x)$).

$y=f(x)$    $\int f(x) = F(x)$
$x^n$$\frac{x^{n+1}}{n+1}+C x^{-1}$$ ln(x)+C$ for $x>0$
$ln(-x)+C$ for $x<0$
$cos(ax)$$-sin(ax)/a+C sin(ax)$$cos(ax)/a+C$
$tan(ax)$$ln(sec^2(ax))/a+C e^{ax}$$e^{ax}/a+C$
$ln(ax)$$x(ln(ax)-1)+C$

Example 18.1

$I=\int 2x^3 dx$

$I=\frac{2x^4}{4}+C$

$I=\frac{x^4}{2}+C$

Example 18.2

$I=\int cos(3x) dx$

$I=sin(3x)/3+C$

Example 18.3

$I=\int sin(4x) dx$

$I=-cos(4x)/4+C$

Polynomial expressions may be integrated term by term. If we have an expression like $3x^2-2x+5$ the integral would be:

$I=\int (3x^2-2x+5)dx$

$=\frac{3x^3}{3}-\frac{2x^2}{2}+5x+C$

$I=x^3-x^2+5x+C$

Expressions that include a function of a linear factor may be integrated using a substitution. If we want to integrate $(4x+3)^5$ we let $4x+3=u$. Differentiating we get $4dx=du$ so $dx=du/4$. Substituting into the integral we get

$I=\int (4x+3)^5dx$

$=\frac{1}{4}\int u^5du$

$=\frac{1}{4} \frac{u^6}{6}+C$

$I=\frac{(4x+3)^6}{24}+C$

An expression like $I=\int \frac{2x+23}{2x^2+x-10}dx$ cannot be integrated using the table of standard integrals but it is possible that we can simplify the expression using partial fractions. First we need to see whether we can factorise the denominator.

You can probably see that $2x^2+x-10=(2x+5)(x-2)$ so we want to can write

 $\frac{2x+23}{2x^2+x-10}$ $=$ $\frac{A}{2x+5}+\frac{B}{x-2}$ $=$ $\frac{A(x-2)+B(2x+5)}{(2x+5)(x-2)}$ so $2x+23$ $=$ $A(x-2)+B(2x+5)$ Let $x=2$ then $4+23=B(4+5)$ so $B=3$ Let $x=-5/2$ then $-5+23=A(-5/2-2)$ so $A=4$ so $I$ $=$ $\int \frac{2x+23}{2x^2+x-10}dx$ can be written $I$ $=$ $\int \frac{4}{2x+5}dx+\int \frac{3}{x-2}dx$ Integrating we get $I$ $=$ $4 ln(2x+5)/2+3 ln(x-2)+C$ so $\int \frac{2x+23}{2x^2+x-10}dx$ $=$ $2 ln(2x+5)+3 ln(x-2)+C$

We know $\frac{d}{dx}(uv)=v\frac{du}{dx}+u\frac{dv}{dx}$

If we integrate this equation we get $(uv)=\int v\frac{du}{dx}dx+\int u\frac{dv}{dx}dx$

Rearranging this we get $\int v\frac{du}{dx}dx=uv-\int u\frac{dv}{dx}dx$

If we have to integrate an expression like $x sin(x)$ we could let $v=x$ and $du=sin(x)$

which means $dv=dx$ and $u=-cos(x)$

so $\int x sin(x) dx=-x cos(x)-\int (-cos(x))dx$

$=-x cos(x)+sin(x) +C$

$\int x sin(x)=sin(x)-x cos(x)+C$