-
Notifications
You must be signed in to change notification settings - Fork 0
/
appdx1.Rmd
5523 lines (3385 loc) · 251 KB
/
appdx1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(reshape2)
palette(c(palette()[1:4], "chocolate2", palette()[6:8]))
```
```{r "source-functions", echo=FALSE}
root_int_fun <- function(y) {
which(sapply(1:(length(y)-1), function(i)
y[i] < 0 && y[i+1] >= 0 || y[i] >= 0 && y[i+1] < 0))
}
```
# Refresher Mathematics{#math}
In this appendix, we go through a few mathematical concepts useful in understanding statistics. You can read this in one session or refer to specific sections as need be.
Concepts we intend to refresh on are:
1. [Ratios, Proportions, Percentages and Rates](#math1)
1. [Introduction to Set theory](#math2)
1. [Basic algebra](#math3)
1. [Operations on Polynomials](#math4)
1. [Factoring Polynomials](#math5)
1. [Scientific Notation](#math6)
1. [Rational Exponents and Radicals](#math7)
1. [Linear Equations and Inequalities in One Variable](#math8)
1. [Quadratic Equations](#math9)
1. [Other Pre-Calculus Topics](#math10)
1. [Elementary Functions](#math11)
1. [Graphs and Transformations](#math12)
1. [Introduction to Calculus](#math13)
```{r "installation-loading-a1", echo=FALSE}
if(!("reshape2" %in% installed.packages()[, "Package"])) {
install.packages("reshape2")
}
```
## Ratios, Proportions, Percentages and Rates{#math1}
Ratios, proportions, percentages and rates are some of the most widely used mathematical concepts in reporting statistical outputs. They involve simple calculations but if not well understood they might lead to mis-reporting. It is for this reason that we go through these concepts in this section.
### Ratios{#ratios}
Ratios are basically comparison of two numbers called **terms**, for example a comparison of the number of girls to boys in a classroom. They can also be viewed as a relationship between two numbers.
Ratios are expressed as $a \text{ to } b$, $a \text{ per } b$, $a:b$ or simply as a fraction.
As an example, let us report number of female smokers to male smokers from this data.
```{r "ratios-a1"}
(tab1 <- table(tips$sex, tips$smoker))
m <- tab1[1, 2]/tab1[2, 2]
```
Here are ways of reporting:
- There are 33 female smokers to 60 male smokers, or even better
- There is one female smoker for every 1.55 male smoker
#### Proportions
Proportions are fractions/parts of a whole. In statistics, proportions are used to quantify or determine representation of a given category/observations in a variable. For example, a teacher in a class would be interested in knowing fraction/proportion of girls/boys in a class.
Given data shown below, let us try and compute proportions of each gender by their smoking habits.
```{r proportions}
(gender.smoker <- table(tips$sex, tips$smoker))
```
We should get this
```{r}
pt <- prop.table(table(tips$sex, tips$smoke)); pt
```
#### Percentages
Percentages express part of a whole as a part of 100, simply put they are proportions multiplied by 100.
From our previous example, we can get percentages by multiplying proportions by 100.
```{r percentages}
perc <- pt * 100; perc
```
#### Rates
Rates are ratios (comparison of two values) whose terms are measured in different units.
For example, in athletics, we could measure athletes speed in terms of distance covered by time like 52 kilometers for four hours (52km per 4hrs).
Rates can be reduced to **unit rate** which are rates expressed as quantity of 1. In our example, athletes speed can be noted as 13km per hour (13km/h).
## Introduction to Set Theory{#math2}
In our probability chapter, we will use a lot of set notation and concepts. For that reason in this section we refresh on elementary concepts of set theory. We shall review two issues:
- [Set Properties and notation](#properties-and-notations)
- [Set Operations](#set-operations)
### Set Properties and Notation{#properties-and-notation}
A set is a collection of objects or things. Sets are denoted by capital letters such as A, B and C.
Objects in a set are called **elements** or **members** of a set. $\in$ notation is used to show an element is a member of a set, for example $c \in A$ which means $c$ is an element in set $A$. $\notin$ is used to show an element is not a member of a given set.
A set without any element is referred to as an **empty** or **null** set. For example a set of all negative values in 1:10. Empty sets are denoted with $\varnothing$ notation.
To refer to a complete set, it's elements are enclosed in curly brackets for example "{1, 2, 3, 4, 5}" for set with numbers 1 through five.
Other than listing all values in a set, a <u>rule</u> can be used to indicate properties of a set it contains, for instance a set of all values above a given number.
Let us expound on this, suppose we had data on heights of children and we wanted only those above a certain height, we can express this in set notation by using a set builder like this:
$$\{height | height_{x} > 3ft 2inc\}$$
Where:
{} are used to denote a set (of variable height)
| means "such that" (in other setting "|" can be replaced with ":")
This expression is read as, "a set of all heights such that height is greater than 3 feet and 2 inches". Therefore variable height must contain height above 3ft 2inc.
For each rule a listing can generated, listing are possible elements meeting rule condition. If a listing continues indefinitely then "..." can be used to show this pattern of continuity. For example:
Rule | Listing
---------------------------------|--------------------
{x|x is an alphabetical letter} | {`r letters`}
{x|x^2 = 9} | {-3, 3}
{x|x is an even number} | {2, 4, 6, ...}
First two examples are referred to as **finite sets** (elements can be counted and there is an end) while the second is referred to as **infinite sets** (there is no end to counting elements).
If each element in a set is in another set for example all elements of set A are in set B, then set A is a **subset** of set B. Note, a set can also be a subset to it's self, in this case they are said to be **equal**. Symbols used to denote these relationships are $\subset$ for subset, $=$ for equality (two set have equal elements), $\notin$ for not a subset, and $\neq$ for two sets without same elements.
It's been been proven a null or empty ($\varnothing$) set is a subset of all sets though this proof is beyond scope of this section.
Set of all elements under consideration is called a **universal set** denoted by $U$.
### Set Operations{#set-operations}
There are four basic set operations, these are:
+ Union
+ Intersection
+ Complement and
+ Difference
Set operations are best shown using a **venn diagram**. A Venn diagram is a display showing all possible logical relationships between a finite collection of different sets. These diagrams consist of overlapping circles within a rectangle. Overlapping area indicates similar elements and rectangle indicates universal set.
**Union set**
Union of sets is a combination of all elements of sets under consideration. For example, union of set A with elements {a, b, c} and set B with elements {c, d, e} is {a, b, c, d, e}. Note we only have unique values in output of a union.
Symbolically, A union B can be shown as $A \cup B$, where $\cup$ denotes union.
Diagrammatically this can be shown as:
![Shaded area: A union B](figures/venn_union_a1.png)
**Intersection**
Intersect is a set of elements that are all sets of interest, basically a set of similar non-unique elements. Symbolically this can be shown as; $A \cap B$ where $\cap$ means intersection.
Diagrammatically this can be show as:
![Shaded area: A intersect B](figures/venn_intersect_a1.png)
Sets A and B are said to be **disjoint** if they share no similar element or $A \cap B = \varnothing$.
![Disjointed sets](figures/venn_disjoint_a1.png)
**Complement**
A complement is a set of elements not contained in a set of interest. For example, a universal set $U$ contains all elements, and set $A$ contains a few elements from this universal set, all elements in $U$ and not in $A$ are complements of $A$. Complement set are denoted with $'$ for instance $A'$ which is read as "$A$ prime".
Using a Venn diagram this can be shown as:
![Shaded area: complement set](figures/venn_complement_a1.png)
**Difference Set**
A set containing only elements not contained in another set; unique elements. For example $A - B$ are all elements in $A$ not contained in $B$.
![Shaded area: A - B](figures/venn_difference_a1.png)
## Basic Algebra{#math3}
Understanding probability theory requires some basic knowledge of algebra which we will use to compute different probabilities. In this regard, in this section we shall look at core concepts in algebra like:
- [Set of real numbers](#real-num)
- [Real number line](#num-line)
- [Real number properties](#num-line-properties) and
- [Fraction properties](#fraction-properties)
### Set of real numbers
A number system is a writing system used to express numbers; they are mathematical notations for representing numbers of a given set.
There are several number systems but most often used number system is the "real number" system.
A real number can be viewed as any number with a decimal representation. Table below shows set of all real numbers and some important subsets.
Symbol | Name | Description | Examples
---------|-----------------|--------------|------------
$\mathbb{N}$ | Natural numbers | Counting numbers (also positive integers) | 1, 2, 3, ...
$\mathbb{Z}$ | Integers | Natural numbers, their negatives, and 0 | ..., -2, -1, 0, 1, 2, ...
$\mathbb{Q}$ | Rational numbers | Numbers which can be represented as a/b, where a and b are integers and b $\neq$ 0; decimal representations are repeating or terminating | -4, 0, 1, 25, $\frac{-3}{5}$, $\frac{2}{3}$, 3.67, -0.33$\overline{3}$, 5.2727$\overline{27}$
$\mathbb{I}$ | Irrational numbers | Numbers which can be represented as non-repeating and non-terminating decimal numbers | $\sqrt{2}$, $\pi$, 1.414213..., 2.71828182...
$\mathbb{R}$ | Real numbers | Rational and irrational numbers |
Source: [Barnett, R.A.](#1)
### Real number line
All real numbers can be positioned as a point on a line referred to as a "real number line". Each point on a real number line corresponds to one real number, this real number is called a **coordinate** of the point.
**Origin** is the point with coordinate 0. Left side of a real number line are "positive real numbers" while on the right side are "negative real numbers". Origin 0 is neutral as it is neither positive nor negative.
![Real number line](figures/real_number_line_a1.png)
### Real number properties
In order to convert algebraic expressions into equivalent forms, some basic properties of real number system are necessary. These properties will be especially useful when discussing calculus.
Here we shall be reviewing four basic properties of a set of real number numbers, these are:
- Associative property
- Commutative property
- Identity property and
- Inverse property
Associative refers to "grouping" or "regrouping" elements (note, this does not mean simplification). Commutative refers to how elements are moved around. An identity is a number which when added to another number equals to the same number. Inverse means opposite or reverse; an inverse is also another number on the real number line when combined on the left or right through operations (+ or *) outputs an identity value.
Under each of these properties, we look at addition, multiplication, and distributive (combination of multiplication and addition) operations.
As examples, we shall use $a, b, \text{ and } c$ as arbitrary elements in a set of real numbers $\mathbb{R}$.
**Addition Properties**
<u>Associative</u>
When elements are grouped or regrouped in an addition computation, output remains the same. That is, whichever way these elements are grouped, output will remain constant.
$$\therefore a + (b + c) = (a + b) + c$$
<u>Commutative</u>
Commutative property of addition states that order of elements does not matter as it results to same output.
$$\therefore a + b = b + a$$
<u>Identity</u>
Here we are looking for a real number (identity) when added to another number results to that number; this number is zero.
$$\therefore 0 + a = a + 0 = a$$
<u>Inverse</u>
Additive inverse is "subtraction", so for "a" a real number, it's inverse is "-a".
$$\therefore a + (-a) = (-a) + a = 0$$
**Multiplicative Properties**
<u>Associative</u>
Just like additive associations, grouping or regrouping elements of a multiplicative operation results in the same output.
$$\therefore a(bc) = (ab)c$$
<u>Commutative</u>
Like commutative property of addition, order of a multiplication operation on elements of a real number line results to same output.
$$\therefore ab = ba$$
<u>Identity</u>
Identity for multiplication is 1
$$\therefore (1)a = a(1) = a$$
Where $a$ is any real $\mathbb{R}$ number
<u>Inverse</u>
Multiplicative inverse (or reciprocal) is "division", so for $a$ a real number, it's multiplicative inverse is $1/a$. Note, "a" cannot be 0 as zero is not defined: 0 cannot be a divisor.
$$\therefore a(1 \div a) = (1 \div a)a = 1$$
**Distributive Properties**
Used when an operation involves both addition and multiplication. This property can also be referred to as "distributive property of multiplication over addition".
This property means that a term multiplied by other terms in parenthesis, simplification should be performed by "distributing" multiplication over terms in parenthesis.
$$\therefore a(b + c) = ab + ac$$
also
$$(a + b)c = ac + bc$$
It is worth noting that, relative to addition, commutativity and associativity are used to change order of addition as well as insert or remove parenthesis as need be. However, the same cannot be done for subtraction and division.
### Additional Properties
Using preceding operations (addition and multiplication), their subtraction and division can be expressed as:
<u>Subtraction</u>
For any real number a and b;
$$a - b = a + (-b)$$
<u>Division</u>
For any real number $a$ and $b$ and where $b \neq 0$;
$$\frac{a}{b} = a(\frac{1}{b})$$
<u>Zero Properties</u>
For all real numbers $a$ and $b$:
1. $a * 0 = 0$
1. $ab = 0 \text{ if and only if } a = 0 \text{ or } b = 0$
### Fraction properties
Division in the form $a \div b$ and where $b \neq 0$ can be written as $\frac{a}{b}$. Top part of this division (element $a$) is called **numerator** and bottom part is called **denominator**.
$$\frac{\text{numerator}}{\text{denominator}}$$
## Operations on Polynomials{#math4}
In this section we refresh on one of the most frequently used mathematical concepts, and that is **Polynomials**. We shall discuss how to work with polynomials which form a core basis in most statistical models. But before that we re-look at exponents and specifically natural number exponents which we will use in our polynomials.
Here are the core concepts we will be reviewing:
1. [Natural Number Exponents](#natural-exponents)
1. [Polynomials](#polynomials)
1. [Shape of Polynomials](#polynomial-shape)
1. [Combining like terms](#like-terms)
1. [Addition and subtraction](#add-subtract)
1. [Multiplication](#multiplication)
1. [Combined operations](#combined)
### Natural Number Exponents{#natural-exponents}
Repeated multiplication of natural numbers (counting numbers or positive integers) $\mathbb{N}$ are often simplified by exponents. Exponents are real numbers $\mathbb{R}$ of multiplication repetitions or multiplication factor. Exponents are also called powers.
For any natural number $a$ multiplied by itself $x$ times can be expressed as:
$$a^x$$
Where:
- $a$ is called a **base** (natural number being multiplied) and
- $x$ is called an **exponent** (multiplication factor)
$a^x$ is read, "$a$ raised to the exponent of $x$".
Two often used exponents are two and three which is base multiplied by itself twice or thrice.
Example:
Exponential form | Expanded form | Output
------------------|-----------------|----------------
$2^2$ | 2 x 2 | `r 2^2`
$2^3$ | 2 x 2 x 2 | `r 2^3`
$2^4$ | 2 x 2 x 2 x 2 | `r 2^4`
#### Exponents{#exponents}
- They tell us how many times a natural number should be multiplied
- A negative exponent means divide (inverse of multiplication)
- A fraction of an exponents like 1/n means taking nth root e.g $7^{\frac{1}{2}}$ = $\sqrt{7}$ and $21^{\frac{1}{3}}$ = $\sqrt[3]{21}$
**Natural Sequence of Exponents**
Rule | Example
------------------------|----------------
$a^1 = a$ | $3^1$ = `r 3^1`
$a^0 = 1$ | $3^0$ = `r 3^0`
$a^{-1} = \frac{1}{a}$ | $3^{-1}$ = `r 1/3^1`
<p id="first-property"><b>First property of Exponents</b></p>
This is also known as **product of exponents properties**. It is used to simplify multiplication of two natural number exponents with similar base.
When two exponents with the same base are multiplied, their expanded form is the same as addition of exponents.
For example, $2^3$ x $2^3$ can be expanded to (2 x 2 x 2) * (2 x 2 x 2) = 2 x 2 x 2 x 2 x 2 x 2; a total of 6 2's. This can be simplified to $2^6$ giving us `r 2^6`.
$$\therefore a^x * a^y = a^{x+y}$$
If there are constants with the same base, multiply them and then add their exponents. For example:
$$10x^2 * 5x^3 = (10*5)x^{2+3} = 50x^5$$
This leads us to our first (and most important) property of exponents; it states that, for any natural number $m$ and $n$, and any real number $b$:
$$b^mb^n = b^{m+n}$$
The following properties can be reasoned in the same way as above:
- $x^m/x^n = x^{m-n}$
- $(x^m)^n = x^{mn}$
- $(xy)^n = x^ny^n$
- $(x/y)^n = x^n/y^n$
- $x^{-n} = 1/x^n$
### Polynomials{#polynomials}
**Algebraic expressions** are numbers (constants/coefficients), symbols (variables like $x$ and $y$) and operators (addition, subtraction, multiplication, division) grouped together to denote a value. Terms are individual objects of an expressions, that is, individual numbers or variables (symbols) or numbers and variables.
![A mathematical expression](figures/expressions_terms_a1.png)
Polynomials are special **algebraic expressions** consisting of several terms. They are formed by constants, variables and non-negative integers exponents combined with addition, subtraction, and multiplication, but not division.
Examples of polynomials | Examples of non-polynomials
---------------------------|----------------------------------
$2x^4 + 3x^7 + 20$ | $\frac{1}{x}$
$2xy^2 + 5xy^3 + 2$ | $2x^{-2} + 5x^2$
$2x + 3x + 1$ | $\frac{a + b}{a^2 - b}$
$5 or 0$ |
Polynomials are constructed with one, two, three or more terms, for example a polynomial with:
- one variable is expressed by adding or subtracting constants and terms of the form $ax^n$
- two variables is expressed by adding or subtracting constants and terms of the form $ax^my^n$
- three variables is expressed by adding or subtracting constants and terms of the form $ax^my^nz^o$
- for more than three variables we use similar pattern as above
#### Classifications of Polynomials by their degree{#degree}
Degree refers to highest exponent in a polynomial. Highest exponent for a one variable polynomial is simply its highest exponent, but for two or more variables, degree is the largest exponent after totaling exponents of each term. For example, $6xy^2 + 3xy^4 +2$ is a 5 degree polynomial because first term has an exponent of $1 + 2 = 3$, second term has an exponent of $1 + 4 = 5$ and final term which is a constant has an exponent of 0.
Degree can be written as deg($6xy^2 + 3xy^4 + 2$) = 5
Below is a table with names of degrees for equations with one variable.
<p id="polynomial-names" style="bold">Names of degrees</p>
Degree | Name | Example
---------|--------------|-------------
0 | Constant | 5
1 | Linear | $2x + 10$
2 | Quadratic | $2x^2 + 5$
3 | Cubic | $2x^3 + x + 3$
4 | Quartic | $2x^4 + 2x^2 + 6$
5 | Quintic | $2x^5 + 3x + 2x^2 + 3$
Note:
- higher order equations (those with high degree; > 2) are harder to solve
- Polynomials are often written with highest degree first, this is called **standard form**
- polynomials of one variable are easy to plot as they have smooth and continuous lines
- A single [term polynomial]{#polynomials-terms} is called **monomial**, a two-term polynomial **binomial** and three-term polynomial **trinomial**
### Shape of polynomials{#polynomial-shape}
Shape of a polynomial's graph is connected to its degree; for odd-degree polynomials ($f(x)$ = $x$ or $x^3$ or $x^5$), with a positive coefficient, graph starts from the negative and ends on the positive and across the x-axis at least once. For even polynomials ($f(x)$ = $x^2$ or $x^4$ or $x^6$) with a positive coefficient, graph starts positive and ends in the positive. Even polynomials can cross x-axis once, twice or not all.
Graphs of polynomial functions are continuous meaning they do not have holes or breaks. In addition, these graphs do not have sharp corners as one would expect from a graph of an absolute function.
[Each]{#vertex} graph of a polynomial with a certain degree has an expected minimum number of **vertices**. Vertices for this continuous graphs are points separating an increasing portion and a decreasing portion or vice versa.
In general, graph of a polynomial function of a positive degree $n$ can have at most $(n-1)$ vertices which can cross the x-axis at most $n$ times.
```{r "polynomial_function_graph-a1"}
op <- par("mfrow")
par(mfrow = c(2, 3))
# First-degree polynomial
x <- seq(-5, 5, 0.01)
plot(c(-5, 5), c(-5, 5), type = "n", ylab = FALSE)
lines(x, 0.5*x, col = 4)
title("First-degree polynomial", line = 1)
title(xlab = "x", ylab = "h(x)", line = 2)
title(sub = "n = 1, therefore 0 vertices", line = 3)
text(4.2, -1.4, labels = expression(paste("f(x) = ", 0.5*x)), srt = 90)
# Third-degree polynomial
third <- expression(x^3 - 2*x)
third_vertices <- c(-sqrt(2/3), sqrt(2/3))
x <- sort(c(third_vertices, seq(-2, 2, 0.01)))
plot(c(-5, 5), c(-5, 5), type = "n", ann = FALSE)
lines(x, eval(third), col = 4)
title("Third-degree polynomial", line = 1)
title(xlab = "x", ylab = "j(x)", line = 2)
title(sub = "n = 3, therefore 2 vertices", line = 3)
points(third_vertices, y = eval(third)[which(x %in% third_vertices)], pch = 21, bg = 4)
text(4.2, 0, labels = expression(paste("j(x) = ", x^3 - 2*x)), cex = 0.9, srt = 90)
# Fifth-degree polynomial
fifth_vertices <- c(-1.64443286, -0.5439123, 1.64443286, 0.5439123)
x <- sort(c(fifth_vertices, seq(-2, 2, 0.01)))
fifth <- expression(x^5 - 5*x^3 + 4*x + 1)
plot(c(5, -5), c(5, -5), type = "n", ann = FALSE)
title("Fifth-degree polynomial", line = 1)
title(xlab = "x", ylab = "f(x)", line = 2)
title(sub = "n = 5, therefore 4 vertices", line = 3)
lines(x, eval(fifth), col = 4)
x <- fifth_vertices
points(fifth_vertices, eval(fifth), pch = 21, bg = 4)
text(4.2, 0, labels = expression(paste("f(x) = ", x^5 - 5*x^3 + 4*x + 1)), cex = 0.8, srt = 90)
# Second-degree polynomial
x <- seq(-2, 2, 0.01)
second <- expression(x^2 - 2)
plot(c(-4, 4), c(-4, 4), type = "n", ann = FALSE)
title("Second-degree polynomial", line = 1)
title(xlab = "x", ylab = "H(x)", line = 2)
title(sub = "n = 2, therefore 1 vertex", line = 3)
lines(x, eval(second), col = 4)
points(0, -2, pch = 21, bg = 4)
text(3.7, 0, labels = expression(paste("H(x) = ", x^2 - 2)), cex = 0.9, srt = 90)
# Fourth-degree polynomial
fourth <- expression(2*x^4 - 4*x^2 + x - 1)
fourth_prime <- expression(8*x^3 - 8*x + 1)
fourth_vertex <- c(-1.0574538, 0.1270510, 0.9304029)
x <- sort(c(fourth_vertex, seq(-1.7, 1.6, 0.01)))
plot(c(-5, 5), c(-5, 5), type = "n", ann = FALSE)
title("Fourth-degree polynomial", line = 1)
title(xlab = "x", ylab = "J(x)", line = 2)
title(sub = "n = 4, therefore 3 vertices", line = 3)
lines(x, eval(fourth), col = 4)
x <- fourth_vertex
points(x, eval(fourth), pch = 21, bg = 4)
text(4.2, 0, labels = expression(paste("J(x) = ", 2*x^4 - 4*x^2 + x - 1)), cex = 0.8, srt = 90)
# Sixth-degree polynomial
sixth <- expression(x^6 - 7*x^4 + 14*x^2 - x - 5)
sixth_prime <- expression(6*x^5 - 28*x^3 + 28*x - 1)
sixth_vertices <- c(-1.777750, 0.035760, 1.807227, -1.237497, 1.172260)
x <- sort(c(seq(-2.3, 2.3, 0.01), sixth_vertices))
plot(c(-5, 5), c(-5, 5), type = "n", xlab = "x", ylab = "")
lines(x, eval(sixth), col = 4)
x <- sixth_vertices
points(sixth_vertices, eval(sixth), pch = 21, bg = 4)
title("sixth-degree polynomial", line = 1)
title(xlab = "x", ylab = "F(x)", line = 2)
title(sub = "n = 6, therefore 5 vertices", line = 3)
text(4.2, 0, labels = expression(paste("F(x) = ", x^6 - 7*x^4 + 14*x^2 - x - 5)), cex = 0.7, srt = 90)
par(mfrow = op)
```
### Combining like terms{#like-terms}
Like terms are terms with similar variables and exponents but they could have different coefficients (constant preceding a term). For example $10x$ and $6x$ are like terms.
Note, if a term has no constant before a variable, then coefficient is understood to be 1. If no constant appears but a negative (-) sign appears in front, then it is understood to be -1. Example: $5t^3 - t^3 + 6$ has coefficients, 5, -1, and 6
There are some **distributive properties** which are necessary for the process of combining like terms, these are:
1. a(b + c) = (b + c)a = ab + ac
1. a(b - c) = (b - c)a = ab - ac
1. a(b + c + ... + f) = ab + ac + ... + af
Now let's do one example of combining like terms:
$$10xy^2 + 2xy^2 + xy^2 + xy + 3$$
Like terms in this example are our first three terms: $10xy^2$, $2xy^2$, and $xy^2$. $xy$ is not a like term as $y$ does not have exponent 2.
$$\therefore 10xy^2 + 2xy^2 + xy^2 + xy + 3 = (10xy^2+2xy^2+xy^2) + xy + 3 = 13xy^2 + xy + 3$$
Note:
- Where parenthesis are present, we begin by clearing expressions in parenthesis using distributive properties then combine like terms. For example $9(x^2 + y^2) - 3(2x^2 - 3y^2)$ can be simplified to $3x^2 + 18y^2$
- Always work with signs, it can either be positive or negative (except for 0 which is sign-less)
### Addition and subtraction{#add-subtract}
Additions and subtractions of polynomials involves removing parentheses and combining like terms.
Let's add the following three polynomials as our example:
$$5x^2 - 2x + 6 \\
2x^3 +x + 3 \\
-x^3 - 2$$
1. Additional arrangement
$$(5x^2 - 2x + 6) + (2x^3 + x + 3) + (-x^3 - 2)$$
2. Remove parentheses (factoring in signs)
$$5x^2 -2x + 6 + 2x^3 + x + 3 - x^3 - 2$$
3. Putting like terms together (from highest exponent)
$$2x^3 - x^3 + 5x^2 - 2x + x + 6 + 3 - 2$$
4. Simplify like terms
$$x^3 + 5x^2 - x + 7$$
Subtraction of polynomials follows similar procedures.
### Multiplication{#multiplication}
Multiplication of algebraic expressions like polynomials, requires extensive use of distributive properties for real numbers as well as other real number properties.
For this, we shall use the following two polynomials:
$$(3x^3 - 2x^2)(9x^3 + x^2 + 5)$$
We multiply first term with all terms in the second polynomial then second term with all second polynomial's terms. This should result in:
$$27x^6 + 3x^5 + 15x^3 -18x^5 - 2x^4 - 10x^2$$
Putting like terms together simplifies it to:
$$27x^6 - 15x^5 - 2x^4 + 15x^3 - 10x^2$$
Note:
- Products of binomials (two-term polynomials) factors occur frequently thus some handy formulas for their products have been given
<p id="special-products" style="font-weight:bold;">Special Products</p>
1. $(a - b)(a + b) = a^2 - b^2$
1. $(a + b)^2 = a^2 + 2ab + b^2$
1. $(a - b)^2 = a^2 - 2ab + b^2$
### Combined operations{#combined}
For combined operations, polynomials will often have several grouping using different symbols like parentheses "()", brackets "[]" and curly braces "{}".
To simplify these polynomials, it is best to remove these grouping symbols from inside, that is, from "()" to "[]" and finally "{}".
In terms of operations precedence, multiplication and division precede addition and subtraction while taking exponents precedes multiplication and division.
As an example, let's simplify this polynomial:
$$2 + \{4x^2 - [4x^3 - 2x^2(x + 3)]\}$$
Begin by removing inner "()"
$$2 + \{4x^2 - [4x^3 - 2x^3 - 6x^2]\}$$
Remove [] (multipling by -1)
$$2 + \{4x^2 - 4x^3 + 2x^3 + 6x^2\}$$
Remove "{}"
$$2 + 4x^2 - 4x^3 + 2x^3 + 6x^2$$
Now we simplify
$$-2x^3 + 10x^2 + 2$$
## Factoring Polynomials{#math5}
In this section we look at concepts of factoring polynomials which can be quite handy in simplification and graphing.
We will specifically look at:
- [Common Factors](#common-factors)
- [Factoring by grouping](#grouping)
- [Factoring second-degree polynomial](#factoring-second-degree-polynomial)
- [Special Factoring Formulas](#special-factoring-formulas)
- [Factoring Polynomials with rational zero's theorem](#rational-zero-theorem)
### Common Factors{#common-factors}
This is an initial process of factoring and it involves factoring out [factors](#factors) common in all terms.
**Example**
Given
$$6z^2w^3 + 3z^4w^2 - 9z^2w^2$$
we can factor out a common factor which is $3z^2w^2$ giving us:
$$3z^2w^2(2w + z^2 - 3)$$
### Factoring by grouping{#factoring-second-degree-polynomial}
Other than factoring out common factors, terms can be grouped in such a way that it make it efficient to complete factoring process for polynomials. There is no rule of the thumb here, but it is important to take into account sign of each term.
**Example**
Given this function:
$$6z^2 + 3z - 4z - 2$$
we can group it's terms as:
$$3z(2z + 1) - 2(2z + 1)$$
Which become:
$$(3z - 2)(2z + 1)$$
If we multiplied these groups we should get our original function $6z^2 + 3z - 4z - 2$.
### Factoring Second-Degree Polynomial
Second-degree polynomials widely used in statistical models. Some of these polynomials can be simplified to first-degree polynomials with integer coefficients which makes it handy for a number of issues including determining points where $y = f(x) = 0$.
Since not all second-degree polynomials can be transformed to two first degree polynomials, then it is good to start off by checking if it is possible to transform them. We do this using a factorability evaluation called **ac Evaluation**.
For a polynomial
$ax^2 + bx + c$ or $ax^2 + bxy + cy^2$,
we can determine if it has first-degree factors with integer coefficients by:
1. taking a product of $a$ and $c$, that is $ac$ and
1. look for two [factors](#factors) of $ac$ which sum up to $b$ (coefficient of the second term)
If these two factors exist, then polynomial has first-degree factors with integer coefficients and we can label these two factors as $p$ and $q$.
Basically this,
$$pq = ac \qquad{} \text{ and } \qquad{} p + q = b$$
must be satisfied.
Therefore, once we know $p$ and $q$ exist, then we can use our "factoring by grouping" knowledge to formulate these two first degree polynomials.
**Example**
Given $9z^2 + 80z - 9$, we begin by checking if we have $p$ and $q$ such that $pq$ equals $ac$.
In this example, $a = 9$ and $c = -9$, thus $ac = -81$. Two factors which sum to $80$ are $-1$ and $81$, we therefore have $p$ and $q$ and as such we can factor it out using integer coefficients.
We do this by substituting $b$ with $p$ and $q$, grouping them and then factoring out common factors.
$$9z^2 - z + 81z - 9$$
$$(9z^2 - z) + (81z - 9)$$
$$z(9z - 1) + 9(9z - 1)$$
$$(z + 9)(9z - 1)$$
Again if we multiplied $(z + 9)$ with $(9z - 1)$ we should get our original polynomial $9z^2 + 80z - 9$.
### Special Factoring Formulas{#special-factoring-formulas}
There are special factoring formulas generated to ease process of factoring certain polynomials which appear frequently these are:
1. [Perfect square]{#perfect-square}: $u^2 + 2uv + v^2 = (u + v)^2$
1. Perfect square: $u^2 - 2uv + v^2 = (u - v)^2$
1. [Difference of squares]{#diff-sqrs}: $u^2 - v^2 = (u - v)(u + v)$
1. [Difference of cubes]{#diff-cubes}: $u^3 - v^3 = (u - v)(u^2 + uv + v^2)$
1. [Sum of cubes]{#sum-of-cubes}: $u^3 + v^3 = (u + v)(u^2 - uv + v^2)$
Notice pattern being formed by differences, we are multiplying one first degree difference with it's $n - 1$ degree expanded expression. Therefore we can write difference of a fifth exponent as:
$$u^5 - v^5 = (u - v)(u^4 + u^3v + u^2v^2 + uv^3 + v^4)$$
**Examples**
1. $9z^2 - 4y^2$ is the same as $(3z)^2 - (2y)^2$ which can be factored out with difference of squares $(3z - 2y)(3z + 2y)$
1. $6(z - 2)^2 - 4y^2$ can be factored to $[3(z - 2) - 2y][3(z - 2) + 2y]$
### Factoring polynomials with rational zero's theorem{#rational-zero-theorem}
Factoring polynomials of higher degree (> 3) can become quite challenging especially when using techniques already discussed. For that reason it might be good to use other methods.
One method is **Rational Zeros Theorem**. This theory basically locates all $x$ values which equate given function to zero. These $x$ values are are called roots of a function.
This theory uses coefficients of highest term and last term (constant). Its reasoning is that, roots of a function will often be a ratio of a factor of it's constant and it's leading coefficient. Symbolically we can express these possible roots of a function as $\frac{p}{q}$ where $p$ is a factor of it's constant and $q$ is a factor of it's leading coefficient. Take note not all $\frac{p}{q}$ will lead to a root, therefore we need to determine which among them yields a root.
To do this we need to do four things:
1. Arrange polynomial in a decreasing order, that means having highest degree term first and constant last. It also means that all degree terms must be given; for those that are not there a zero term can be added like $0x^3$.
1. Determine all factors of constant and leading coefficient, these includes their negative values.
1. Compute all combinations of $\frac{p}{q}$ and eliminate any duplicates 1. Use division method to determine $\frac{p}{q}$'s that are roots.
Let us go over one example to grasp this concept.
**Example**
Given
$$j(x) = -5x^4 - 4x^3 + 42x^2 + 12x - 45$$
we want to find all its roots. From our basic algebra we know these must total to 4 since it is a fourth-degree polynomial.
Our initial activity is to order our polynomial and include 0 terms where needed. Since our polynomial is in good order, then we can proceed to our next activity.
From our equation $p$ is -45 and $q$ is -5, factors of $p$ are 1, 3, 5, 9, 15, 45 and their negatives. Factors of $q$ are 1, 5 and their negatives.
Now we need to get all unique combinations of $\frac{p}{q}$. These are:
```{r}
p <- c(1, 3, 5, 9, 15, 45)
q <- c(1, 5)
possible_vals1 <- expand.grid(p, q)
possible_vals2 <- expand.grid(p, -1 * q)
possible_vals <- rbind(possible_vals1, possible_vals2)
p_over_q <- possible_vals[,1]/possible_vals[,2]
p_over_q <- unique(p_over_q)
p_over_q
```
Our final step is to determine which among these $\frac{p}{q}$ are roots. We shall do this by dividing our function by a one degree polynomial formed by each of these $p/q$'s. Therefore we will have our equation as our divided and each of these one degree polynomials will be our divisor. Idea here is to determine which outputs a zero remainder. We should also note that dividing by a one degree polynomial leads to divided being a polynomial of a lesser degree. By reducing these polynomials we are left with polynomials which we can solve for $x$ using previously discussed methods.
For our initial division, we will have our dividend as
$$-5x^4 - 4x^3 + 42x^2 + 12x - 45$$
and our divisor for $\frac{p}{q} = 1$ as $x - 1$
We can now determine its quotient and remainder as we do with any other division.
$$x - 1 )\overline{-5x^4 - 4x^3 + 42x^2 + 12x - 45}$$
Core idea about this division is to determine terms which output zero when subtracted from a divided's term but divisible by leading term of divisor. Therefore we begin by dividing first term of our divided with first term of our divisor, output should be able to equate first term to zero when it is subtracted. In this case $-5x^4$ divided by $x$ is $-5x^3$ which we place above our division bar.
$$-5x^3\\
x - 1) \overline{-5x^4 - 4x^3 + 42x^2 + 12x - 45}$$
We proceed by multiplying $-5x^3$ by our divisor $x + 1$ to get $-5x^4 + 5x^3$ and place it right below our divided first two terms.
$$-5x^3\\
x + 1) \overline{-5x^4 - 4x^3 + 42x^2 + 12x - 45}\\
-5x^4 + 5x^3\qquad{} \qquad{} \qquad{} \quad{}$$
We follow this by subtracting $-5x^3 + 5x^3$ from $-5x^4 - 4x^3$ and place output below line under $-5x^4 + 5x^3$.
$$-5x^3\qquad{}\qquad{}\qquad{}\qquad{}\qquad{}\\
x + 1) \overline{-5x^4 - 4x^3 + 42x^2 + 12x - 45}\\
-5x^4 - 5x^3\qquad{} \qquad{} \qquad{} \quad{}\\
\overline{\qquad{}\qquad{} -9x^3}\qquad{}\qquad{}\qquad{}\qquad{}$$
If we continues with this pattern then we should obtain a quotient of $-5x^3 - 9x^2 + 33x$ and a 0 remainder. This means 1 is a zero root of $j$.
As you must have noticed, doing this division is rather involving but if we take a closer look we will see a pattern to simplify this process.
Two things to take note in this pattern, leading term of our divisor is only used to clear terms in our divided (equating them to zero). The other thing to note is that our variables do not matter in our division as long as they are complete and in a decreasing order. What is of concern to us are coefficients of our divided and second term of our divisor.
Given these facts, we should see that leading term of our quotient ($-5x^3$) has same coefficient asleading term of our divided ($-5x^4$) but with one degree less. Coefficient of our second quotient ($-9$) is a difference of second term of our divided ($-4$) and product of leading coefficient and second term of our divisor ($-5 * -1 = 5$). Coefficient of third term in our quotient ($33$) is a difference of coefficient of third term in our divided and product of second difference ($-9$) and second term of our divisor ($-9 * -1 = 9$). Fourth term of our quotient (45) is a difference of coefficient of fourth term of our divided ($12x$) and product of third difference (33) and second term of our divisor ($33 * -1 = -33$).
To make this computation simple to work with, we will do additions rather than difference for our $p/q$. For clarity, we will form a line with our $p/q$ on our left and coefficients of our divided on on our right. We can then take totals after taking note that our leading coefficient will always be coefficient of leading term in our divided.
In essence we should have something like this
$$1\rfloor \qquad{}\qquad{} -5\quad{}-4\quad{}42\quad{}12\quad{}-45\quad{}\\
\qquad{}\qquad{}\qquad{} -5\quad{}-9\quad{}33\quad{}45\\
\text{_________________________________}\\
\qquad{}\qquad{} -5\quad{}-9\quad{}33\quad{}45\quad{}0$$
Since we have a remainder zero which is what we got with our division, then this reasoning is correct and we can do this with other $p/q$.
But before running through all other $p/q$'s , let us appreciate a few facts from this output. A remainder zero means we have reduced our fourth degree by 1 thus becoming a third-degree polynomial.
$$h(x) = -5x^3 - 9x^2 + 33x + 45$$
Something else to note is that we can take our new function $-5x^3-9x^3+33x+45$ and use other methods to locate zeros. But with efficiency of computer programs, we can easily run through all our $p/q$'s using our simplified method and establish -3 is also a root $j$.
We are therefore left with two other roots to determine.
```{r "polynomial-division"}
coeffs <- c(-5, -4, 42, 12, -45)
n <- length(p_over_q)
remainder <- sapply(1:n, function (i)
((((coeffs[1]*p_over_q[i]) + coeffs[2]) *
p_over_q[i] + coeffs[3]) *
p_over_q[i] + coeffs[4]) *
p_over_q[i] + coeffs[5])
remainder
zeros1 <- p_over_q[which(remainder == 0)]
```
To get these last two roots we need to use our new function $h$. This function has different coefficients (-5, -9, 33, and 45) but has same $p/q$ since constant and leading coefficents are similar. Therefore running through all our $p/q$'s again we get -3 as a root of $h$.
Since we did not get our two last roots, we can use reduced function from running -3.
```{r, echo=FALSE}
coeffs2 <- c(coeffs[1], rep(NA, length(coeffs)-2))
coeffs2[2] <- coeffs2[1] * p_over_q[zeros1[1]] + coeffs[2]
coeffs2[3] <- coeffs2[2] * p_over_q[zeros1[1]] + coeffs[3]
coeffs2[4] <- coeffs2[3] * p_over_q[zeros1[1]] + coeffs[4]
n <- length(p_over_q)
remainder2 <- sapply(1:n, function(i)
(((coeffs2[1]*p_over_q[i]) + coeffs2[2]) *
p_over_q[i] + coeffs2[3]) *
p_over_q[i] + coeffs2[4])
coeffs3 <- c(coeffs2[1], rep(NA, length(coeffs2)-2))
coeffs3[2] <- coeffs3[1] * -3 + coeffs2[2]
coeffs3[3] <- coeffs3[2] * -3 + coeffs2[3]
coeffs3[4] <- coeffs3[3] * -3 + coeffs2[4]
```
This new function is a second-degree polynomial
$$-5x^2 + 6x + 15$$
This is now much simpler function to work with as there are quite a number of methods for determining roots of a second degree polynomial. One method is a [quadratic (second-degree polynomial) formula](#quadratic-formula) which we will discuss later, but for purposes of solving our second-degree polynomial we will mention how it is used.
For a general quadratic equation
$$ax^2 + bx + c = 0 \qquad{} a \ne 0$$
$x$ can be solve with this quadratic formula
$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$
Therefore, from our quadratic equation $-5x^2 + 6x + 15$, $a = -5, \text{ }b = 6 \text{ and } c = 15$.
We substitute this values in our formula
$$x = \frac{-6 \pm \sqrt{-6^2 - 4(-5)(15)}}{2(-5)}$$
```{r}
x1 <- (-6 + sqrt((-6)^2 - 4*-5*15))/(2*-5)
x2 <- (-6 - sqrt((-6)^2 - 4*-5*15))/(2*-5)
hx_at_zero <- c(-3, -1.23303, 1, 2.43303)
```
Output from this formula are our last two roots `r x1` and `r x2`.
In conclusion, $j(x) = 0$ or roots of $j$ occurs when $x = -3, -1.2330, 1 \text{ and } 2.43303$
## Scientific Notation{#math6}
Large and small numbers are often expressed in exponential form for ease of writing and manipulation. This exponential form is said to be in "Scientific notation".
Numbers expressed in scientific notation are expressed as:
$$a * 10^x \qquad{} 1 \leqslant a < 10$$
where
- $a$ a decimal value and
- $x$ is an integer
This means a finite decimal value can be expressed as a product of a number between 1 and 10 and an integer exponent of base 10. Positive exponents means number is greater than or equal to 10, negative exponent means number is greater than 0 but less than 1, while zero exponents means number is greater than or equal to 1 but less than 10.
A simple way to think of this is to count how many decimal places to add a zero (due to base 10). If exponent is positive, then we move decimal place to the right, if exponent is negative we move decimal place to the left.
Examples:
Decimal Notation | Scientific Notation
---------------------|---------------------------
100 | $1 x 10^2$
1,000 | $1 x 10^3$
9,600,000,000 | $9.6 x 10^9$
0.2 | $2 x 10^{-1}$
0.0000036 | $3.6 x 10^{-6}$
Most calculators and statistical programs can calculate in either decimal or scientific notation, but they often output scientific notation when value is large or small. Their scientific notation is often in form of a decimal value followed by letter $e/E$ then exponent and it's sign, for example 3.6e-06 for 0.0000036.
## Rational Exponents and Radicals{#math6}
In this section we discuss:
1. [Fractional exponents](#fractional-exponents)
1. [nth Root of Real Numbers](#nth-root)