-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathFoundationsMathematics.Rnw
More file actions
4943 lines (3475 loc) · 130 KB
/
FoundationsMathematics.Rnw
File metadata and controls
4943 lines (3475 loc) · 130 KB
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
\documentclass[12pt]{book}
\usepackage{Sweave}
%% added by SV:
\usepackage{hyperref}
\hypersetup{colorlinks=TRUE,linkcolor=blue,anchorcolor=blue,filecolor=blue,pagecolor=blue,urlcolor=blue,citecolor=blue,bookmarksnumbered=true}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{gauss}
\usepackage[latin1]{inputenc}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{courier}
%
\usepackage{type1cm}
\usepackage{makeidx} % allows index generation
\usepackage{graphicx} % standard LaTeX graphics tool
% when including figure files
\usepackage{multicol} % used for the two-column index
\usepackage[bottom]{footmisc}% places footnotes at page bottom
\usepackage{amsthm}
\usepackage{esint}
\usepackage{cancel}
\usepackage{comment}
\excludecomment{answer}
%\includecomment{answer}
\usepackage{framed}
\setcounter{secnumdepth}{5}
%\newcommand{\vect}[1]{\boldsymbol{#1}}
\newcommand{\vect}[1]{\vec{#1}}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{fact}{Fact}
\newtheorem{proposition}{Proposition}
\usepackage[table]{xcolor}
\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}
\usepackage{mathtools}
\makeatletter
\newcommand{\explain}[2]{\underset{\mathclap{\overset{\uparrow}{#2}}}{#1}}
\newcommand{\explainup}[2]{\overset{\mathclap{\underset{\downarrow}{#2}}}{#1}}
\makeatother
%% taken from http://brunoj.wordpress.com/2009/10/08/latex-the-framed-minipage/
\newsavebox{\fmbox}
\newenvironment{fmpage}[1]
{\begin{lrbox}{\fmbox}\begin{minipage}{#1}}
{\end{minipage}\end{lrbox}\fbox{\usebox{\fmbox}}}
\hyphenation{distribu-tion}
\newcommand{\BlackBox}{\rule{1.5ex}{1.5ex}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\SweaveOpts{prefix.string=figures/statsnotesfig}
%\SweaveOpts{cache=TRUE}
\title{Foundations of Mathematics\\
\small
Lecture notes for the MSc in Cognitive Systems at the University of Potsdam, Germany
}
\author{Compiled by Shravan Vasishth}
\date{version of \today}
\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em}
\DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em}
\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
\SweaveOpts{keep.source=TRUE}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
\tableofcontents
<<echo=FALSE>>=
## customize
options(prompt="> ", continue=" ",
show.signif.stars=FALSE)
options(width=50)
options(SweaveHooks=list(fig=function() par(bg="white", fg="black")))
@
\chapter{Preface}
These notes are intended to serve as lecture notes for the \href{http://www.ling.uni-potsdam.de/en/students/msc-cogsys}{MSc Cognitive Systems} foundational course \textit{Foundations of Mathematics}.
The notes are based on the books listed in the references, and on the graduate certificate course taught at the School of Mathematics and Statistics (SOMAS), University of Sheffield, UK.
An important piece of advice I have for students taking this course is that when you get stuck with a problem, don't just give up. Sometimes you will have to keep at it for some hours or days (intense effort, trying different lines of attack) to solve a problem. One trick that works for me is to put in intense effort, and then take a break (usually involved going to sleep at night---I often work on math problems last thing at night). When you return to the problem the next time round, you may see the solution right away.
Homework assignments are integral to the course, but these are provided only to students taking the course.
Solutions are usually provided a week after the assignment is handed out. The homework assignments are not graded; the student is expected to evaluate their mistakes on their own by comparing the provided solutions with their own attempt. The assignments will however be discussed in class, so that there is ample opportunity for discussion of any problems that come up.
The formal examination for this course is a 20 minute oral exam that the instructor will conduct at the end of the course.
The offical textbook for the course is \cite{gilbertjordan}; \textbf{please get the second edition, published in 2002}. A good, additional text (if you can afford it) is \cite{jordansmith4e}; \textbf{if you buy this too, please get the fourth edition, published in 2008}.
I owe a great debt of gratitude to \href{http://maths.dept.shef.ac.uk/maths/staff_info_498.html}{Fionntan Roukema} at SOMAS, Sheffield. He is the best math teacher I have ever encountered, and his teaching style has been an inspiration to me.
\chapter{Course schedule}
We have approximately 14 lectures in this course (this varies a bit from year to year).
The approximate schedule is as follows:
\begin{enumerate}
\item Precalculus I (HW0 assigned)
\item Discussion of solutions to HW0
\item Precalculus II (HW1 assigned)
\item Solutions HW1
\item Differentiation (HW2 assigned)
\item Solutions HW2
\item Integration (HW3 assigned)
\item Solutions HW3
\item Matrix Algebra I (HW4 assigned)
\item Matrix Algebra II, minima, maxima, partial derivatives (HW 5 assigned)
\item Solutions HW4 and HW5
\item Double integrals, change of variables (HW 6)
\item Solutions HW6
\item Review, and applications in statistics and data mining (time permitting)
\end{enumerate}
%To-do for next iteration: show applications early, and add more exercises, and add references to video lectures. Extend the lecture notes.
\chapter{Pre-calculus review}
Sources: heavily depended on \cite{salas2003calculus}, \cite{spivak}, \cite{gilbertjordan} (the official textbook in the course) and various summaries on the internet on trigonometric functions.
\section{Counting}
The number of ways in which one may select an unordered sample of k subjects from a population that has n distinguishable members is
\begin{itemize}
\item
$\frac{(n-1+k)!}{[(n-1)!k!]}$ if sampling is done with replacement,
\item
${n \choose k}=\frac{n!}{[k!(n-k)!]}$ if sampling is done without replacement.
\end{itemize}
\begin{table}[!htbp]
\caption{default}
\begin{center}
\begin{tabular}{c|cc}
& ordered = TRUE & ordered = FALSE\\
\hline
replace = TRUE & $n^{k}$ & $(n-1+k)! / [(n-1)!k!]$ \\
replace = FALSE & $n! / (n-k)!$ & ${n \choose k}$
\end{tabular}
\end{center}
\label{default}
\end{table}%
\section{Permutations and combinations}
\subsection{Permutations}
For $n$ objects, of which $n_1,\dots , n_r$ are alike, the number of different permutations are
\begin{equation}
\frac{n!}{n_1!n_2!\dots n_r!}
\end{equation}
\subsection{Combinations}
Choosing $k$ distinct objects from $n$, when order irrelevant:
\begin{equation}
{n \choose k} = \frac{n!}{(n-r)! r!}
\end{equation}
\subsection{Binomial theorem}
\begin{equation}
(x+y)^n = \underset{n=0}{\overset{n}{\sum}} {n \choose k} x^k y^{n-k}
\end{equation}
%\section{Algebra review}
%to-do
\section{Inequalities}
To solve an inequality, we need to determine the numbers $x$ that satisfy the inequality. This is called the \textbf{solution set} of the inequality.
\begin{enumerate}
\item If we multiply or divide an inequality by a negative number, the inequality is reversed.
Example: $-\frac{1}{2} x < 4$
\item To solve a quadratic inequality,
you can always solve it by completing the square. Another way is to factor the quadratic (works sometimes).
%%p 12 Salas
Example: Solve $x^2 - 4x + 3 > 0$.
Example (use completing the square): Solve $x^2 - 2x + 5 \leq 0$.
\end{enumerate}
\section{Series}
\subsection{Arithmetic series}
General form:
\begin{equation}
a+(a+d)+(a+2d)+\dots
\end{equation}
$k$-th partial sum for \textbf{arithmetic series}:
\begin{equation}
S_k = \underset{n=1}{\overset{k}{\sum}} (a+(n-1)d)
\end{equation}
The sum can be found by:
\begin{equation}
S_k = \frac{k}{2} (2a+(k-1)d)
\end{equation}
\subsection{Geometric series}
General form:
\begin{equation}
a+ar+ar^2\dots
\end{equation}
In summation notation:
\begin{equation}
\underset{n=1}{\overset{\infty}{\sum}} ar^{n-1}
\end{equation}
$k$-th partial sum:
\begin{equation}
S_k=\frac{a-(1-r^k)}{1-r}
\end{equation}
$S_\infty$ exists just in case $\mid r \mid < 1$.
\begin{equation}
S_\infty = \frac{a}{1-r}
\end{equation}
%\subsection{Clever trick for computing partial sums of geometric series}
%to-do (see my P-Ass1 solution)
\subsection{Power series}
\begin{equation}
\underset{n=0}{\overset{\infty}{\sum}} a_n (x-a)^n
\end{equation}
%\textbf{radius of convergence}: to-do
\section{Trigonometry}
\subsection{Basic definitions}
\begin{figure}[!htbp]
\centering
\includegraphics[width=6cm]{triangle}
\caption{Right-angled triangle.}
\label{fig:tri}
\end{figure}
\begin{equation}
\sin A = \frac{opp}{hyp} = \frac{a}{c}
\end{equation}
Cosine is the complement of the sine:
\begin{equation}
\cos A = \sin (90-A) = \sin B
\end{equation}
\begin{equation}
\cos A = \frac{b}{c}
\end{equation}
\subsection{Pythagorean identity}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
\begin{split}
\frac{a^2}{c^2} + \frac{b^2}{c^2} & = 1\\
\sin^2 A + \cos^2 A & = 1
\end{split}
\end{equation}
\subsection{Relations between trig functions}
\begin{equation}
\tan A = \frac{\sin A}{\cos A} = \frac{a}{c}/\frac{b}{c}= \frac{a}{b} =
\frac{opp}{adj}
\end{equation}
$\tan A$ is also the \textbf{slope} of a line.
\begin{equation}
\cot A = \frac{1}{\tan A}=\frac{\cos A}{\sin A}
\end{equation}
\begin{equation}
\sec A = \frac{1}{\cos A}
\end{equation}
\begin{equation}
\csc A = \frac{1}{\sin A}
\end{equation}
%\begin{figure}[!htbp]
\begin{center}
\begin{fmpage}{.6\linewidth}
\begin{tabular}{c|c}
sin A = a/c (opp/hyp) & csc A = c/a (hyp/opp)\\
cos A = b/c (adj/hyp) & sec A = c/b (hyp/adj)\\
tan A = a/b (opp/adj) & cot A = b/a (adj/opp)\\
\end{tabular}
\end{fmpage}
\end{center}
%\end{figure}
Note that cot A = tan B, and csc A = sec B.
\subsection{Identities expressing trig functions in terms of their complements}
\begin{center}
\begin{fmpage}{.5\linewidth}
\begin{tabular}{c|c}
cos t = sin($\pi$/2-t) & sin t = cos($\pi$/2-t)\\
cot t = tan($\pi$/2-t) & tan t = cot($\pi$/2-t)\\
csc t = sec($\pi$/2-t) & sec t = csc($\pi$/2-t)\\
\end{tabular}
\end{fmpage}
\end{center}
\subsection{Periodicity}
\begin{center}
\begin{fmpage}{.5\linewidth}
\begin{tabular}{c|c}
$\sin t + 2\pi = \sin t$ & $\sin t + \pi = -\sin t$\\
$\cos t + 2\pi = \cos t$ & $\cos t + \pi = -\cos t$\\
$\tan t + 2\pi = \tan t$ & $\tan t + \pi = \tan t$\\
\end{tabular}
\end{fmpage}
\end{center}
\begin{center}
\begin{fmpage}{.6\linewidth}
\begin{tabular}{ccc}
$\sin 0 = 0$ & $\cos 0 = 1$ & $\tan 0 = 0$ \\
$\sin \frac{\pi}{2} = 1$ & $\cos \frac{\pi}{2} = 0$ & $\tan \frac{\pi}{2}$ undefined \\
$\sin \pi = 0$ & $\cos \pi = -1$ & $\tan \pi = -1$ \\
\end{tabular}
\end{fmpage}
\end{center}
\subsection{Law of cosines}
Three ways of writing it:
\begin{equation}
c^2 = a^2 + b^2 - 2ab \cos C
\end{equation}
\begin{equation}
a^2 = b^2 + c^2 - 2bc \cos C
\end{equation}
\begin{equation}
b^2 = c^2 + a^2 - 2ca \cos C
\end{equation}
\subsection{Law of sines}
\begin{equation}
\frac{\sin A}{a}=\frac{\sin B}{b}=\frac{\sin C}{c}
\end{equation}
\subsection{Odd and even functions}
A function $f$ is said to be an odd function if for any number $x$, $f(-x) = -f(x)$ (e.g., $f(y)=x^5$). A function $f$ is said to be an even function if for any number $x$, $f(-x) = f(x)$ (e.g., $f(y)=x^4$).
Odd functions: sin, tan, cotan, csc.
Even functions: cos, sec.
%$\sin $ is odd ($\sin -t=-\sin t $), $\cos$ is even ($\cos -t=\cos t $).
\subsection{Sum formulas for sine and cosine}
\begin{equation}
\sin (s + t) = \sin s \cos t + \cos s \sin t
\end{equation}
\begin{equation}
\cos (s + t) = \cos s \cos t - \sin s \sin t
\end{equation}
\subsection{Double angle formulas for sine and cosine}
\begin{equation}
\sin 2t = 2 \sin t \cos t
\end{equation}
\begin{equation}
\cos 2t = \cos^2 t - \sin^2 t = 2 \cos^2 t - 1 = 1 - 2 \sin^2 t
\end{equation}
\subsection{Less important identities}
Pythagorean formula for tan and sec:
\begin{equation}
\sec^2 t = 1 + \tan^2 t
\end{equation}
Identities expressing trig functions in terms of their supplements
\begin{equation}
\sin(\pi - t) = \sin t
\end{equation}
\begin{equation}
\cos(\pi - t) = -\cos t
\end{equation}
\begin{equation}
\tan(\pi - t) = -\tan t
\end{equation}
Difference formulas for sine and cosine
\begin{equation}
\sin (s - t) = \sin s \cos t - \cos s \sin t
\end{equation}
\begin{equation}
\cos (s - t) = \cos s \cos t + \sin s \sin t
\end{equation}
\chapter{Differentiation and integration}
\section{Differentiation}
Given a function $f(x)$, the derivative from first principles is as follows:
If we want to find $\frac{\partial y}{\partial x}$, note that $\partial y = f(x+\partial x) - f(x)$:
\begin{equation}
\begin{split}
y =& f(x)\\
y+\partial y =& f(x+\partial x) \\
\end{split}
\end{equation}
Subtracting y from both sides:
\begin{equation}
\begin{split}
y+\partial y - y =& f(x+\partial x) -y \\
\partial y =& f(x+\partial x) -f(x) \\
\end{split}
\end{equation}
It follows that $\frac{\partial y}{\partial x} = \frac{f(x+\partial x) -f(x) }{\partial x}$. If we write the first derivative $\frac{\partial y}{\partial x}$ as $f^{(1)}(x)$, we have the following identity:
\begin{equation}
f^{(1)}(x)= \frac{f(x+\partial x) - f(x)}{\partial x}
\end{equation}
Other notations we will use interchangeably: Given y = f(x),
$\frac{\partial y}{\partial x}=\frac{d y}{d x}=f^{(1)}(x)=y'$.
Note:
\begin{enumerate}
\item
The derivative of a function at some point c is the slope of the function at that point c. The slope is the rate of growth: $\frac{dy}{dx}$.
\item
The derivative $f'$ is itself a function, and can be further differentiated. So, the second derivative, $f''$ is the rate of change of the slope. This will soon become a very important fact for us when we try to find maxima and minima of a function.
\end{enumerate}
\subsection{Deriving a rule for differentiation}
Consider the function $y=x^2$. Suppose we increase x by a small amount $dx$, y will also increase by some small amount $dy$. We can ask: what is the ratio of the increases: $\frac{dy}{dx}$? We will derive this next:
\begin{equation}
y + dy = (x+dx)^2
\end{equation}
Expanding out the RHS:
\begin{equation}
y + dy = x^2+dx^2+2xdx
\end{equation}
Observe that squaring a small quantity dx will make it even smaller (e.g., try squaring 1/100000000; it is effectively zero). That leads to the following simplification:
\begin{equation}
y + dy = x^2+2xdx \hbox{ as dx gets infinitesimally small}
\end{equation}
Subtracting y from both sides:
\begin{equation}
dy = 2xdx \Leftrightarrow \frac{dy}{dx} = 2x
\end{equation}
\textbf{Exercise}: Find the derivative of $x^3, x^4, x^5$ using the above approach. Evaluate each derivative at c=2.
The general rule is that
\begin{equation}
\boxed{\frac{dy}{dx} = nx^{n-1}}
\end{equation}
Verify that this rule works for negative powers and fractional powers:
$x^{-2}, x^{1/2}$.
\subsection{Derivatives of trigonometric functions, exponential, and log}
Memorizing these results will simplify our life considerably.
\begin{enumerate}
\item
$\frac{d(\sin(x))}{dx} = \cos x$ and $\frac{d(\cos(x))}{dx} = -\sin x$.
\item
$d(\exp(x))/dx=\exp(x)$
\item
$d(\log(x))/dx = \frac{1}{x}$
\end{enumerate}
Proofs will come later.
\subsection{Derivations of combinations of functions}
Let u and v be (differentiable) functions.
\begin{enumerate}
\item Sum of functions
\begin{equation}
(u+v)' = u' + v'
\end{equation}
\item Difference of functions
\begin{equation}
(u-v)' = u' - v'
\end{equation}
\item Function multiplied by constant:
Given a constant c:
\begin{equation}
(cu)' = cu'
\end{equation}
\item Product of functions
\begin{equation}
(uv)' = uv' + vu'
\end{equation}
\item Quotient of functions:
\begin{equation}
(u/v)' = \frac{vu' - uv'}{v^2}
\end{equation}
\item
Chain rule:
If y = g(f(x)), then, letting u=f(x), we get $dy/dx= dy/du \cdot du/dx$
Example: $y=(x^2 + 3)^7$ needs the chain rule.
\end{enumerate}
Note: the notation $\frac{dy}{dx}\bigg |_{x=a}$ means: evaluate the derivative at x=a.
Given one of our standard functions above, which I will call $f(x)$, we can differentiate it repeatedly: $f', f''$, etc.
So:
\begin{enumerate}
\item
$f'(x)=\frac{d}{dx} f(x)$
\item
$f''(x)=\frac{d^2}{dx^2} f(x)$
\item
$f'''(x)=\frac{d^3}{dx^3} f(x)$
\end{enumerate}
\subsection{Maxima and minima}
If we have a function like $y=f(x)$, there may be a point (for some x) where the graph of this function turns over. For example, in the normal distribution (see chapter\~ref{apps}), the graph turns over at the mean.
At this turning point, the slope changes from positive to negative, and is 0 at the turning point. Therefore,
\begin{equation}
f'(x)
\end{equation}
is an equation whose solution is the point where the graph turns over.
Note that a graph does not necessarily turn over at a point where $f'(x)=0$. Example: $y=x^3$.
<<fig=TRUE>>=
x<-seq(-10,10,by=0.1)
plot(x,x^3,type="l")
@
If $f'(x)=0$ at some point x=c, then this point c is called the stationary point of $f(x)$. This point could be a local maximum or a local minimum. To determine whether this point is a local maximum or minimum, take the second derivative: $f''(x)$.
\begin{enumerate}
\item
If $f'(c)=0$ and $f''(c)<0$, then we have a local maximum.
\item
If $f'(c)=0$ and $f''(c)>0$, then we have a local minimum.
\item
If $f'(c)=0$ and $f''(c)=0$, then we have either a maximum, mininum, or a stationary point of inflection like in the $y=x^3$ figure above. In this case, examine the sign of $f'(x)$ on both sides of $x=c$.
\end{enumerate}
\section{Integration}
\subsection{Riemann sums}
A simple example:
Given $\phi (x)$, the probability density function of the standard normal distribution:
\begin{equation*}
\phi (x) = \frac{1}{\sqrt{2\pi}} e^{-x^{2}/2}
\end{equation*}
We have to find an approximate value of
\begin{equation*}
\int_0^1 \phi (x)\, dx
\end{equation*}
We divide the interval $[0,1]$ into $10$ intervals of width $1/10$, and approximate the area under the curve by taking the sum of the $10$ rectangles under the curve. The width of each rectangle will be $\partial x=1/10$, and each of the ten $x_i$ are $1/10,2/10,\dots,10/10$, i.e., $i/10$, where $i=1,\dots, 10$.
The area $A$ can be computed by summing up the areas of the ten rectanges. Each rectangle's area is length $\times$ width, which is $\phi(x_i) \times \partial x$. Hence,
\begin{equation*}
A= \underset{i=1}{\overset{10}{\sum}} \phi(x_i) \partial x = \underset{i=1}{\overset{10}{\sum}}
\frac{1}{\sqrt{2\pi}} e^{-x_i^{2}/2} \times \frac{1}{10}
\end{equation*}
The constant terms $\frac{1}{\sqrt{2\pi}}$ and $\frac{1}{10}$ can be pulled out of the summation:
\begin{equation*}
A= \frac{1}{\sqrt{2\pi}} \frac{1}{10}
\underset{i=1}{\overset{10}{\sum}}
e^{-x_i^{2}/2}
\end{equation*}
We use R for the above calculations. First, we define the function for $e^{-x_i^{2}/2}$:
<<>>=
my.fn<-function(x)
{exp(1)^(-(x^2/2))}
@
Then we define $x_i$ (I made the code very general so that the number of intervals $n$ can be increased arbitrarily) and plug this into the function:
<<print=TRUE>>=
n<-10
x.i<-(1:n)/n
A<- ((1/n) * (1/sqrt(2 * pi)) * sum(my.fn(x.i)))
A<-round(A,digits=5)
@
Compare this to the exact value, computed using R:
<<>>=
fprob2<-function(x){
(1/sqrt(2 * pi))*exp(1)^(-(x^2/2))
}
integrate(fprob2,lower=0,upper=1)
@
\textbf{Answer}: The approximate area is: $\Sexpr{A}$. This is a bit lower than the value computed by R, but this is because the ten rectangles fall inside the curve.
<<>>=
## As an aside, note that one can get really close
## to the pnorm value by increasing n,
## say to a high number like 2000:
n<-2000
## 2000 rectangles now:
x.i<-(1:n)/n
(A<- ((1/n) * (1/sqrt(2 * pi)) * sum(my.fn(x.i))))
@
With 2000 rectangles, we can get a better estimate of the area than with 10 rectangles: \Sexpr{round(A,4)}. Compare this with the
theoretical value:
<<>>=
round(pnorm(1)-pnorm(0),4)
@
\subsection{Some common integrals}
\begin{equation}
\int \frac{1}{x}\, dx = \log \mid x \mid + c
\end{equation}
\begin{equation}
\int \log x\, dx = \frac{1}{x} + c
\end{equation}
\subsection{The Fundamental Theorem of Calculus}
The Fundamental Theorem states the following:
Let $f$ be a continuous real-valued function defined on a closed interval $[a, b]$. Let $F$ be the function defined, for all $x$ in $[a, b]$, by
\begin{equation*}
F(x) = \int_a^x f(u)\, du
\end{equation*}
Then, $F$ is continuous on $[a, b]$, differentiable on the open interval $(a, b)$, and
\begin{equation*}
F'(x) = f(x)
\end{equation*}
for all $x $ in $(a, b)$.
%\subsection{Rules of integration} to-do
%\subsection{Standard integrals} to-do
\subsection{The u-substitution}
From \cite[306]{salas2003calculus}:
An integral of the form
\begin{equation}
\int f(g(x)) g'(x) \, dx
\end{equation}
can be written as
\begin{equation}
\int f(u) \, du
\end{equation}
by setting
\begin{equation}
u = g(x)
\end{equation}
and
\begin{equation}
du = g'(x) \, dx
\end{equation}
If F is an antiderivative for f, then
\begin{equation}
\frac{d}{dx} [F(g(x))] \explain{=}{\textrm{by the chain rule}} F'(g(x)) g'(x) \explain{=}{F'=f} f(g(x)) g'(x)
\end{equation}
We can obtain the same result by calculating:
\begin{equation}
\int f(u) \, du
\end{equation}
and then substituting g(x) back in for u:
\begin{equation}
\int f(u) \, du = F(u)+C = F(g(x)) + C
\end{equation}
\textbf{A frequently occurring type of integral} is
\begin{equation}
\int \frac{g'(x)}{g(x)} \, dx
\end{equation}
Let $u=g(x)$, giving $\frac{du}{dx}=g'(x)$, i.e., $du = g'(x)\,dx$, so that
\begin{equation}
\int \frac{g'(x)}{g(x)}\,dx=\int \frac{1}{u} du = ln \mid u \mid +C
\end{equation}
\begin{center}
\begin{fmpage}{.5\linewidth}
\textbf{Examples}:
\begin{equation*}
\int \tan x \, dx = \int \frac{1}{\cos x} \sin x \, dx
\end{equation*}
\begin{equation*}
\int \frac{2x + b}{x^2+bx + c} \, dx
\end{equation*}
\end{fmpage}
\end{center}
\textbf{Functions of linear functions}: E.g., $\int cos(2x-1)\,dx$. Here, the general form is $\int f(ax+b)\,dx$. We do $u=ax+b$, and then $du=a \,dx$
\begin{center}
\begin{fmpage}{.9\linewidth}
\textbf{Using integration by substitution to compute the expectation of a standard normal random variable}:
The expectation of the standard normal random variable:
\begin{equation*}
E[Z] = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^\infty x e^{-x^2/2} \, dx
\end{equation*}
Let $u = -x^2/2$.
Then, $du/dx = -2x/2=-x$. I.e., $du= -x \, dx$ or $-du=x \, dx$.
We can rewrite the integral as:
\begin{equation*}
E[Z] = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^\infty e^{u} x \, dx\\
\end{equation*}
Replacing $x\, dx$ with $-du$ we get:
\begin{equation*}
-\frac{1}{\sqrt{2\pi}} \int_{-\infty}^\infty e^{u} \, du
\end{equation*}
which yields:
\begin{equation*}
-\frac{1}{\sqrt{2\pi}} [ e^{u} ]_{-\infty}^{\infty}
\end{equation*}
Replacing $u$ with $-x^2/2$ we get:
\begin{equation*}
-\frac{1}{\sqrt{2\pi}} [ e^{-x^2/2} ]_{-\infty}^{\infty} = 0
\end{equation*}
\end{fmpage}
\end{center}
\subsection{Change of variables (Gamma functions)}
We can solve integrals like
\begin{equation}
\int_0^\infty x^2 e^{-x^5}\, dx
\end{equation}
by restating it as the gamma function:
\begin{equation}
\Gamma (z) = \int_0^\infty x^{z-1}e^{-x}\, dx
\end{equation}
This can be done by, e.g., letting $y=x^5$, so that $dy/dx= 5x^4$, and therefore $dx= dy/5x^4 = dy/(5\times y^{4/5})$. This lets us rewrite the above integral in terms of y:
\begin{equation}
\frac{y^{2/5}}{5y^{4/5}}e^y\, dy
\end{equation}
This has the form of the gamma function, allowing us to state the integral in terms of the gamma function.
Note that
\begin{equation}
\Gamma(z) = (z-1) \Gamma (z-1)
\end{equation}
R has a function, gamma, that allows us to compute $\Gamma(z)$:
<<>>=
gamma(2)
gamma(10)
## this is equal to:
(10-1)*gamma(10-1)
@
\chapter{Matrix algebra}
[Some of this material is based on \cite{jordansmith4e}.]
A rectangular array of numbers (real numbers in our case) which obeys certain algebraic rules of operations is a matrix.
The main application for us will be in solving systems of linear equations in statistics (and in data mining).
Example of a 2x2 matrix:
<<>>=
## a 2x2 matrix:
(m1<-matrix(1:4,2,2))
## transpose of a matrix:
t(m1)
@
\section{Introductory concepts}
\subsection{Basic operations}
Matrix addition and subtraction are cell-wise operations:
<<>>=
m1+m1
m1-m1
@
Matrix multiplication:
Think of this simple situation first, where you have a vector of values:
<<>>=
(m1<-rnorm(5))
@
If you want to find out the sum of the squares of these values ($\overset{n}{\underset{i=1}\sum} x_i ^2$), then you can multiply each value in m1 with itself, and sum up the result:
<<>>=
(sum(m1*m1))