-
Notifications
You must be signed in to change notification settings - Fork 3
/
04-Chapter_4.Rmd
138 lines (93 loc) · 2.91 KB
/
04-Chapter_4.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
# (PART) Review of math and statistics {-}
# Basic mathematical tools {#chapter4}
## The summation operator {.unnumbered}
## Exponents {.unnumbered}
## Equations {.unnumbered}
## Simultaneous equations {.unnumbered}
R can perform standard matrix algebra operations. We can use matrix algebra functions in R to solve our problem from class.
$$
7x + 5y - 3z = 16 \\
3x -5y +2z = -8 \\
5x +3y -7z = 0
$$
First, we rewrite the system using matrix and vector notation:
$$
\mathbf{A} = \left[\begin{array}
{rrr}
7 & 5 & -3 \\
3 & -5 & 2 \\
5 & 3 & -7 \\
\end{array}\right]
\mathbf{b} = \left[\begin{array}
{rrr}
x \\
y \\
z \\
\end{array}\right]
\mathbf{r} = \left[\begin{array}
{rrr}
16 \\
-8 \\
0 \\
\end{array}\right]
$$
In order to obtain the result vector *b*, we have to rearrange the model performing some simple matrix algebra operations.
$$
\mathbf{A}^{-1}\mathbf{A}\mathbf{b} = \mathbf{A}^{-1}\mathbf{r} \\
\text{remember that} \space \mathbf{A}^{-1}\mathbf{A} = \mathbf{I} \\
\mathbf{b} = \mathbf{A}^{-1}\mathbf{r}
$$
We are now ready to solve our system of equations using R:
```{r}
data <- c(7, 5, -3, 3, -5, 2, 5, 3, -7)
A <- matrix(data, nrow = 3, ncol = 3, byrow = TRUE)
r <- c(16, -8, 0)
b <- solve(A) %*% r
b
```
## Logarithms {.unnumbered}
## Derivatives {.unnumbered}
## Optimization {.unnumbered}
## Derivative rules {.unnumbered}
**The rules for sums and differences**
Given $ f(x) = g(x) \pm h(x) $, where $g(x)$ and $h(x)$ are both differentiable functions, the derivative of a sum or difference of two functions is given by:
\begin{equation}
f'(x) = g'(x) \pm h'(x)
\end{equation}
**The product rule**
Given $f(x) = g(x) \cdot h(x)$, where $g(x)$ and $h(x)$ are both differentiable functions, the derivative is given by:
\begin{equation}
f'(x) = h(x) \cdot g'(x) + h'(x) \cdot g(x)
\end{equation}
**The quotient rule**
Given $f(x) = \frac{g(x)}{h(x)}$, where $g(x)$ and $h(x)$ are both differentiable functions and $h(x)\neq0$, the derivative is given by:
\begin{equation}
f'(x) = \dfrac{h(x) \cdot g'(x) - h'(x) \cdot g(x)}{[h(x)]^2}
\end{equation}
**The generalized power function rule**
Given $f(x) = [g(x)]^n$, where $g(x)$ is a differentiable functions and n is any real number, the derivative is given by:
\begin{equation}
f'(x) = n[g(x)]^{n-1} \cdot g'(x)
\end{equation}
**The chain rule**
Given $f(x) = h(g(x))$, where $f$ is a function of a function where $h$ is in turn function of \textit{g}, the derivative is given by:
\begin{equation}
f'(x) = h'(g(x)) \cdot g'(x)
\end{equation}
**Additional rules**
Given $f(x) = e^x$, the derivative is given by:
\begin{equation}
f'(x) = e^x
\end{equation}
Given $f(x) = ln(x)$, the derivative is given by:
\begin{equation}
f'(x) = \frac{1}{x}
\end{equation}
Given $f(x) = sin(x)$, the derivative is given by:
\begin{equation}
f'(x) = cos(x)
\end{equation}
Given $f(x) = cos(x)$, the derivative is given by:
\begin{equation}
f'(x) = -sin(x)
\end{equation}