-
Notifications
You must be signed in to change notification settings - Fork 2
/
04-vector-operations.Rmd
630 lines (452 loc) · 23.6 KB
/
04-vector-operations.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
# Vector Operations {#vecop}
In this chapter you will learn about some of the common arithmetic operations (addition, subtraction, and multiplication) that can be performed with vectors. As in the previous chapter, you will also be introduced to the geometry of these vector operations in 2-dimensional space.
```{r echo=FALSE}
x = data.frame(x = -15:15)
y = data.frame(y = -15:15)
fake_graph = tidyr::crossing(x, y)
graph_paper = ggplot(data = fake_graph, aes(x = x, y = y)) +
geom_point(alpha = 0) +
theme_light() +
scale_x_continuous(name ="", breaks = -15:15, labels = NULL, expand = c(0, 0)) +
scale_y_continuous(name = "", breaks = -15:15, labels = NULL, expand = c(0, 0)) +
geom_segment(
x = 0, xend = 0, y = 15, yend = -15, arrow = arrow(length = unit(0.02, "npc"), end = "both", type = "closed")
) +
geom_segment(
x = -15, xend = 15, y = 0, yend = 0, arrow = arrow(length = unit(0.02, "npc"), end = "both", type = "closed")
) +
theme(
panel.grid = element_line(color = "#60CDE4"),
panel.grid.minor = element_blank()
)
```
<br />
## Vector Addition and Subtraction
Vectors can be added together if they have the same dimensions (i.e., they have the same number of elements and are both row or column vectors). To add two vectors, each of length *n*, together, we sum the corresponding elements in the vectors. For example, consider the column vectors **a** and **b**, where,
$$
\mathbf{a} = \begin{bmatrix}5 \\ 2\end{bmatrix} \qquad \mathbf{b} = \begin{bmatrix}1 \\ 3\end{bmatrix}
$$
Since both vectors have dimensions $2 \times 1$, we can compute the sum of these vectors as:
$$
\begin{split}
\mathbf{a} + \mathbf{b} &= \begin{bmatrix}5 \\ 2\end{bmatrix} + \begin{bmatrix}1 \\ 3\end{bmatrix} \\[2ex]
&= \begin{bmatrix}5 + 1 \\ 2 + 3\end{bmatrix} \\[2ex]
&= \begin{bmatrix}6 \\ 5\end{bmatrix}
\end{split}
$$
Note that the resulting vector is a column vector with two elements, the same as the vectors we summed together. In general, if we sum two *n*-dimensional column vectors, **x** and **y**, the resulting vector will also be an *n*-dimensional column vector:
$$
\begin{split}
\mathbf{x} + \mathbf{y} &= \begin{bmatrix}x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_n\end{bmatrix} + \begin{bmatrix}y_1 \\ y_2 \\ y_3 \\ \vdots \\ y_n\end{bmatrix} \\[2ex]
&= \begin{bmatrix}x_1 + y_1 \\ x_2 + y_2 \\ x_3 + y_3 \\ \vdots \\ x_n + y_n\end{bmatrix}
\end{split}
$$
This process is similar for summing two *n*-dimensional row vectors, except the resulting vector will be an *n*-dimensional row vector.
<br />
### Geometry of Adding Vectors
Geometrically, adding two vectors, say **a** and **b**, is equivalent to drawing vector **b** so that its tail is placed at the head of vector **a**. Then the sum is the new vector that originates at vector **a**'s tail and terminates at vector **b**'s head. Figure \@ref(fig:fig04-01) geometrically shows the sum of the following vectors:
$$
\mathbf{a} = \begin{bmatrix}
5 \\ 2
\end{bmatrix} \qquad \mathbf{b} = \begin{bmatrix}
1 \\ 3
\end{bmatrix} \qquad \mathbf{a}+\mathbf{b} = \begin{bmatrix}
6 \\ 5
\end{bmatrix}
$$
```{r fig04-01, echo=FALSE, fig.width=6, fig.height = 6, out.width='60%', fig.cap="Plot showing the sum of vector **a** (in red) and vector **b** (in blue) in the R1--R2 dimensional space. For convenience we have located the tail of vector **a** at the origin. The vector that corresponds to the sum of **a** and **b** is shown in purple."}
graph_paper +
geom_segment(x = 0, y = 0, xend = 5, yend = 2, color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 5, y = 2, xend = 6, yend = 5, color = "#1A5C71",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 0, y = 0, xend = 6, yend = 5, color = "#C1A7C5",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4) +
annotate("text", x = 3, y = 0.5, label = "(5, 2)", hjust = 0, size = 4, color = "#FF2D21") +
annotate("text", x = 6.5, y = 3, label = "(1, 3)", vjust = 1, size = 4, color = "#1A5C71") +
annotate("text", x = 3, y = 3.8, label = "(6, 5)", vjust = 1, size = 4, color = "#C1A7C5")
```
<br />
### Vector Subtraction
To subtract vector **b** from vector **a**, we subtract the corresponding elements in vector **b** from those in vector **a**. For example, working with our previously defined vectors,
$$
\begin{split}
\mathbf{a} - \mathbf{b} & = \begin{bmatrix}
5 \\ 2
\end{bmatrix} - \begin{bmatrix}
1 \\ 3
\end{bmatrix} \\[2ex]
&= \begin{bmatrix}
5-1 \\ 2 - 3
\end{bmatrix} \\[2ex]
&= \begin{bmatrix}
4 \\ -1
\end{bmatrix}
\end{split}
$$
Since subtraction is equivalent to adding the inverse, subtracting the elements of **b** from **a** is equivalent to adding the inverted elements of **b** to the elements of **a** (where "inverting the elements" means switching the sign on each element). For example,
$$
\begin{split}
\mathbf{a} - \mathbf{b} & = \mathbf{a} + -\mathbf{b} \\[2ex]
&= \begin{bmatrix}
5 \\ 2
\end{bmatrix} + \begin{bmatrix}
-1 \\ -3
\end{bmatrix}
\end{split}
$$
Figure \@ref(fig:fig04-02) geometrically shows the operation of vector subtraction by adding the inverse of **b** to **a**.
```{r fig04-02, echo=FALSE, fig.width=6, fig.height = 6, out.width='60%', fig.cap="Plot showing the sum of vector **a** (in red) and the inverted vector **b** (in blue) in the R1--R2 dimensional space. For convenience we have located the tail of vector **a** at the origin. The vector that corresponds to the difference of **a** and **b** is shown in purple."}
graph_paper +
geom_segment(x = 0, y = 0, xend = 5, yend = 2, color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 5, y = 2, xend = 4, yend = -1, color = "#1A5C71",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 0, y = 0, xend = 4, yend = -1, color = "#C1A7C5",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4) +
annotate("text", x = 3, y = 2, label = "(5, 2)", size = 4, color = "#FF2D21") +
annotate("text", x = 5.5, y = 1, label = "(-1, -3)", size = 4, color = "#1A5C71") +
annotate("text", x = 1.5, y = -1, label = "(4, -1)", vjust = 1, size = 4, color = "#C1A7C5")
```
<br />
### Properties of Vector Addition and Subtraction
In vector addition, since each corresponding element is added, vector addition satisfies both the commutative and associative properties. That is,
$$
\mathbf{a} + \mathbf{b} = \mathbf{b} + \mathbf{a}
$$
and
$$
\begin{split}
\mathbf{a} + (\mathbf{b} + \mathbf{c}) &= (\mathbf{a} + \mathbf{b}) + \mathbf{c} \\[2ex]
&= \mathbf{a} + \mathbf{b} + \mathbf{c}
\end{split}
$$
Convince yourself these two properties are satisfied using the following vectors.
$$
\mathbf{a} = \begin{bmatrix}5 \\ 2\end{bmatrix} \qquad \mathbf{b} = \begin{bmatrix}1 \\ 3\end{bmatrix} \qquad \mathbf{c} = \begin{bmatrix}2 \\ 0\end{bmatrix}
$$
Since we can re-write vector subtraction as vector addition, these same conditions and properties also apply for vector subtraction.
<br />
## Vector--Scalar Multiplication
When a vector is multiplied by a scalar, each element of the vector is multiplied by the value of the scalar. Consider the following vector **a** and scalar $\lambda$,
$$
\mathbf{a} = \begin{bmatrix}2 \\ 3 \\ 0 \\ -1\end{bmatrix} \qquad \lambda=3
$$
Multiplying **a** by $\lambda$ gives:
$$
\begin{split}
\lambda\mathbf{a} &= 3\begin{bmatrix}2 \\ 3 \\ 0 \\ -1\end{bmatrix} \\[2ex]
&= \begin{bmatrix}3 \times 2 \\ 3 \times 3 \\ 3 \times 0 \\ 3 \times -1\end{bmatrix} \\[2ex]
&= \begin{bmatrix}6 \\ 9 \\ 0 \\ -3\end{bmatrix}
\end{split}
$$
This same method applies to row vectors. Scalars may be fractions, negative numbers, or unknowns. For example, if the scalar $\gamma$ is an unknown scalar, then
$$
\gamma\mathbf{a} = \begin{bmatrix}2\gamma \\ 3\gamma \\ 0 \\ -1\gamma\end{bmatrix}
$$
<br />
### Division by a Scalar
Technically, division is undefined for vectors. However, if we are dividing by a scalar, we can multiply the vector by the scalar's reciprocal. For example, using our previously defined vector **a** and scalar $\lambda$,
$$
\mathbf{a} \div \lambda \quad \mathrm{does~not~exist}
$$
But, we can multiply by the reciprocal of $\lambda$, namely $\dfrac{1}{\lambda}$. For example, using the values from our previous example:
$$
\begin{split}
\mathbf{a} = \begin{bmatrix}2 \\ 3 \\ 0 \\ -1\end{bmatrix} \quad &\mathrm{and} \quad \lambda = 3 \\[2ex]
\frac{1}{\lambda}\mathbf{a} &= \frac{1}{3}\begin{bmatrix}2 \\ 3 \\ 0 \\ -1\end{bmatrix} \\[2ex]
&= \begin{bmatrix} \frac{2}{3} \\ 1 \\ 0 \\ -\frac{1}{3}\end{bmatrix}
\end{split}
$$
<br />
### Geometry of Vector--Scalar Multiplication
Consider the product $\lambda \mathbf{a}$ where,
$$
\lambda = 2 \quad \mathrm{and} \quad \mathbf{a} = \begin{bmatrix}
2 \\ 3
\end{bmatrix}
$$
The product is
$$
\begin{bmatrix}
4 \\ 6
\end{bmatrix}
$$
To show what happens geometrically when we multiply a vector by a scalar, let's examine a plot of the original vector and the product.
```{r fig04-03, echo=FALSE, fig.width=8, fig.height = 4, out.width='90%', fig.cap="LEFT: Plot showing vector **a** in the R1--R2 dimensional space. RIGHT: Plot showing vector 2(**a**) in the R1--R2 dimensional space. For convenience we have located the tail of both vectors at the origin."}
p1 = graph_paper +
geom_segment(x = 0, y = 0, xend = 2, yend = 3, color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4)
p2 = graph_paper +
geom_segment(x = 0, y = 0, xend = 4, yend = 6, color = "#1A5C71",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4)
# Display
p1 | p2
```
Multiplying vector **a** by 2 doubled its length. However the direction of the new vector is the same as the original. In general, multiplying a vector by a positive scalar changes the length of a vector but not the direction. If it is multiplied by a negative scalar, not only does the length of the resulting vector change, but its direction is $180^\circ$ from the original. For example, Figure \@ref(fig:fig04-04) shows vector **a** and the vector $\lambda \mathbf{a}$ where $\lambda = -0.5$.
```{r fig04-04, echo=FALSE, fig.width=8, fig.height = 4, out.width='90%', fig.cap="LEFT: Plot showing vector **a** in the R1--R2 dimensional space. RIGHT: Plot showing vector -0.5(**a**) in the R1--R2 dimensional space. For convenience we have located the tail of both vectors at the origin."}
p1 = graph_paper +
geom_segment(x = 0, y = 0, xend = 2, yend = 3, color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4)
p2 = graph_paper +
geom_segment(x = 0, y = 0, xend = -1, yend = -1.5, color = "#1A5C71",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4)
# Display
p1 | p2
```
The product vector is half the length of the original and is pointed in the complete opposite direction.
<br />
## Vector--Vector Multiplication: Dot Product
For two column vectors, **a** and **b** each having *n* elements, the dot product (i.e., scalar product) is defined as:
$$
\mathbf{a} \bullet \mathbf{b} = \sum_{i=1}^n a_ib_i
$$
In other words, the dot product is calculated by multiplying together the corresponding elements of each vector, and summing those products. Consider the vectors,
$$
\mathbf{a} = \begin{bmatrix}5 \\ 4 \\ 7 \\ 2\end{bmatrix} \qquad \mathbf{b} = \begin{bmatrix}1 \\ 0 \\ -1 \\ 2\end{bmatrix}
$$
The dot product, or $\mathbf{a} \bullet \mathbf{b}$, is calculated as:
$$
\begin{split}
\mathbf{a} \bullet \mathbf{b} &= 5(1) + 4(0) + 7(-1) + 2(2) \\[2ex]
&= 2
\end{split}
$$
Remember that the result of a dot product is a scalar.
<br />
### Re-visiting Vector Length
Recall that to find the length of a vector **a** with *n*-dimensions:
$$
\lvert\lvert \mathbf{a} \rvert\rvert = \sqrt{a_1^2 + a_2^2 + a_3^2 + \ldots + a_n^2}
$$
The sum under the square root is equivalent to computing the dot product of **a** with itself (i.e., $\mathbf{a} \bullet \mathbf{a}$). Therefore, the length of an *n*-dimensional vector **a** can be found by computing the square root of the dot product between **a** and itself:
$$
\lvert\lvert \mathbf{a} \rvert\rvert = \sqrt{\mathbf{a} \bullet \mathbf{a}}
$$
<br />
### Dot Products Using the Special Vectors
In the [previous chapter](#vec) we introduced several special vectors, including zero vectors, ones vectors, and elementary vectors. It is useful to explore what happens when one of these special vectors is used to calculate an dot product.
Consider finding the dot product between an *n*-dimensional vector **a** and an *n*-dimensional zero vector **0**:
$$
\begin{split}
\mathbf{a} \bullet \mathbf{0} &= \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ \vdots \\ a_n \end{bmatrix} \bullet \begin{bmatrix} 0 \\ 0 \\ 0 \\ \vdots \\ 0 \end{bmatrix}\\[2ex]
&= a_1(0) + a_2(0) + a_3(0) + \ldots + a_n(0) \\[2ex]
&= 0
\end{split}
$$
The dot product is 0. Now, consider finding the dot product between an *n*-dimensional vector **a** and an *n*-dimensional ones vector **1**:
$$
\begin{split}
\mathbf{a} \bullet \mathbf{1} &= \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ \vdots \\ a_n \end{bmatrix} \bullet \begin{bmatrix} 1 \\ 1 \\ 1 \\ \vdots \\ 1 \end{bmatrix}\\[2ex]
&= a_1(1) + a_2(1) + a_3(1) + \ldots + a_n(1) \\[2ex]
&= \sum_{i=1}^n a_i
\end{split}
$$
Notice that the dot product here is simply the sum of the elements in **a**. Because of this property, ones vectors are also sometimes referred to as *sum vectors*.
Next, consider finding the dot product between an *n*-dimensional vector **a** and an *n*-dimensional elementary vector, say $\mathbf{e}_1$ in which the first element is 1 and the rest are 0:
$$
\begin{split}
\mathbf{a} \bullet \mathbf{e}_1 &= \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ \vdots \\ a_n \end{bmatrix} \bullet \begin{bmatrix} 1 \\ 0 \\ 0 \\ \vdots \\ 0 \end{bmatrix}\\[2ex]
&= a_1(1) + a_2(0) + a_3(0) + \ldots + a_n(0) \\[2ex]
&= a_1
\end{split}
$$
Notice that the dot product here is simply the same as the first element in **a**. In general, the dot product between an *n*-element column vector, **a**, and an *n*-element elementary vector, $\mathbf{e}_i$ with element $i=1$, is:
$$
\mathbf{a} \bullet \mathbf{e}_i = a_i
$$
<!-- Technically, the dot product is the product of a row vector and column vector. In our example this is: -->
<!-- $$ -->
<!-- \mathbf{a} \bullet \mathbf{b} = \mathbf{a}^{\prime}\mathbf{b} -->
<!-- $$ -->
<!-- The product of a row vector and a column vector is defined as: -->
<!-- $$ -->
<!-- \begin{split} -->
<!-- \mathbf{a}^{\prime}\mathbf{b} &= \begin{bmatrix}a_1 & a_2 & a_3 & \dots & a_n\end{bmatrix} \begin{bmatrix}b_1 \\ b_2 \\ b_3 \\ \vdots \\ b_n\end{bmatrix} \\[2ex] -->
<!-- &= a_1(b_1) + a_2(b_2) + a_3(b_3) + \ldots + a_n(b_n) \\[2ex] -->
<!-- &= \sum_{i=1}^n a_ib_i -->
<!-- \end{split} -->
<!-- $$ -->
<!-- For example, consider our previous example: -->
<!-- $$ -->
<!-- \begin{split} -->
<!-- \mathbf{a} \bullet \mathbf{b} &= \mathbf{a}^{\prime}\mathbf{b} \\[2ex] -->
<!-- &= \begin{bmatrix}5 & 4 & 7 & 2\end{bmatrix} \begin{bmatrix}1 \\ 0 \\ -1 \\ 2\end{bmatrix} \\[2ex] -->
<!-- &= 5(1) + 4(0) + 7(-1) + 2(2) \\[2ex] -->
<!-- &= 2 -->
<!-- \end{split} -->
<!-- $$ -->
<!-- Some caveats: -->
<!-- - The dot product $\mathbf{a}\bullet\mathbf{b}$ is always the product of $\mathbf{a}^{\prime}\mathbf{b}$. (The row vector is always first in the product; $\mathbf{a}\mathbf{b}^{\prime} \neq \mathbf{a}^{\prime}\mathbf{b}$.) -->
<!-- - It is not possible to find the dot product of more than two vectors. -->
<br />
## Vector Operations Using R
We can also carry out these vector operations using R. Below we show how to carry out the operations of vector addition and vector subtraction.
```{r}
# Create vectors
a = matrix(data = c(5, 2), ncol = 1)
a
b = matrix(data = c(1, 3), ncol = 1)
b
# Vector addition
a + b
# Vector subtraction
a - b
```
Multiplication of a vector by a scalar is carried out using the `*` operator. This operator carries out element-wise multiplication; in this case it multiplies each element in the vector by the given scalar.
```{r}
# Create vectors
a = matrix(data = c(2, 3, 0, -1), ncol = 1)
a
# Multiplication by 3
3 * a
# Division by 3 (this multiplies each element by the reciprical)
a / 3
```
Lastly, although there is no dot product operator, we can mimic this function by using the elemement-wise multiplication operator to find the product of the corresponding elements of two vectors, and then use the `sum()` function to add those products together.
```{r}
# Create vectors
a = matrix(data = c(5, 4, 7, 2), ncol = 1)
a
b = matrix(data = c(1, 0, -1, 2), ncol = 1)
b
# Element-wise multiplication
a * b
# Compute dot product
sum(a * b)
# Compute length of a using dot product
sqrt(sum(a * a))
```
<br />
:::exercises
## Exercises
**Consider the following vectors:**
$$
\mathbf{a} = \begin{bmatrix}1 \\ 2 \\ 4 \end{bmatrix} \qquad \mathbf{b} = \begin{bmatrix}2 \\ 1 \\ -1\end{bmatrix} \qquad \mathbf{c} = \begin{bmatrix}5 \\ 2 \\ 3 \end{bmatrix} \qquad \mathbf{d} = \begin{bmatrix}2 \\ 1 \\ 0 \end{bmatrix} \qquad \mathbf{e} = \begin{bmatrix}1 \\ 3 \\ 2 \end{bmatrix}
$$
1. Find $\mathbf{a}\bullet\mathbf{b}$.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_01');">Show/Hide Solution</button>
<div id="solution_01" style="display:none; margin: -40px 0 40px 40px;">
$$
1(2) + 2(1) + 4(-1) = 0
$$$
</div>
2. Find $\mathbf{c}\bullet\mathbf{c}$.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_02');">Show/Hide Solution</button>
<div id="solution_02" style="display:none; margin: -40px 0 40px 40px;">
$$
5(5) + 2(2) + 3(3) = 38
$$
</div>
<!-- 3. Find $\mathbf{d}^{\intercal}\mathbf{e}$ and $\mathbf{e}^{\prime}\mathbf{d}$ -->
<!-- <button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_10');">Show/Hide Solution</button> -->
<!-- <div id="solution_10" style="display:none; margin: -40px 0 40px 40px;">$5(5) + 2(2) + 3(3) = 38$</div> -->
**Create a 2-dimensional orthogonal reference system. Show the following vector operations on that system.**
3. $\mathbf{x}+\mathbf{y}$ where $\mathbf{x} = \begin{bmatrix}2 \\ -1 \end{bmatrix}$ and $\mathbf{y} = \begin{bmatrix}-3 \\ 2 \end{bmatrix}$
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_03');">Show/Hide Solution</button>
<div id="solution_03" style="display:none; margin: -40px 0 40px 40px;">
$$
\begin{split}
\mathbf{x} + \mathbf{y} &= \begin{bmatrix} 2 \\ -1\end{bmatrix} + \begin{bmatrix} -3 \\ 2\end{bmatrix} \\[2ex]
&= \begin{bmatrix} -1 \\ 1\end{bmatrix}
\end{split}
$$
```{r echo=FALSE, out.width="60%"}
graph_paper +
geom_segment(x = 0, y = 0, xend = 2, yend = -1, color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 2, y = -1, xend = -1, yend = 1, color = "#1A5C71",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
geom_segment(x = 0, y = 0, xend = -1, yend = 1, color = "#C1A7C5",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4) +
coord_cartesian(xlim = c(-5, 5), ylim = c(-5, 5)) +
annotate("text", x = 1, y = -1, label = "x", fontface = "bold", color = "#FF2D21") +
annotate("text", x = 0.5, y = 0.5, label = "y", fontface = "bold", color = "#1A5C71") +
annotate("text", x = -1, y = 0.4, label = "x + y", fontface = "bold", color = "#C1A7C5")
```
</div>
4. $3\mathbf{z}$ where **z** is a unit vector in which all the elements are equal.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_04');">Show/Hide Solution</button>
<div id="solution_04" style="display:none; margin: -40px 0 40px 40px;">
```{r echo=FALSE, out.width="90%", fig.height=4, fig.width=8}
p1 = graph_paper +
geom_segment(x = 0, y = 0, xend = (1/sqrt(2)), yend = (1/sqrt(2)), color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4) +
coord_cartesian(xlim = c(-5, 5), ylim = c(-5, 5)) +
annotate("text", x = 2.5, y = 2.5, label = "z", fontface = "bold", color = "#FF2D21")
p2 = graph_paper +
geom_segment(x = 0, y = 0, xend = 3*(1/sqrt(2)), yend = 3*(1/sqrt(2)), color = "#FF2D21",
arrow = arrow(length = unit(0.02, "npc"), end = "last", type = "closed")
) +
annotate("text", x = 13.5, y = -0.5, label = "R1", size = 4) +
annotate("text", x = 0.65, y = 13.5, label = "R2", size = 4) +
coord_cartesian(xlim = c(-5, 5), ylim = c(-5, 5)) +
annotate("text", x = 2.5, y = 2.5, label = "3z", fontface = "bold", color = "#FF2D21")
# Display
p1 | p2
```
</div>
**Students' scores on two exams ranged from 32 to 98 out of a possible 100 points on both exams. The scores for six students are shown below for Exam 1 (x) and Exam 2 (y).**
$$
\mathbf{x} = \begin{bmatrix}56 \\ 64 \\ 32 \\ 88 \\ 90 \\ 79\end{bmatrix} \qquad \mathbf{y} = \begin{bmatrix}50 \\ 69 \\ 51 \\ 98 \\ 87 \\ 70\end{bmatrix}
$$
5. Determine the total score for each student by finding $\mathbf{z} = \mathbf{x} + \mathbf{y}$.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_05');">Show/Hide Solution</button>
<div id="solution_05" style="display:none; margin: -40px 0 40px 40px;">
$$
\mathbf{z} = \begin{bmatrix}56 + 50 \\ 64 + 69 \\ 32 + 51 \\ 88 + 98 \\ 90 + 87 \\ 79 + 70\end{bmatrix} = \begin{bmatrix}106 \\ 133 \\ 83 \\ 186 \\ 177 \\ 149\end{bmatrix}
$$
</div>
6. Determine the mean score for each student by finding $\frac{1}{2} \mathbf{z}$.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_06');">Show/Hide Solution</button>
<div id="solution_06" style="display:none; margin: -40px 0 40px 40px;">
$$
\frac{1}{2}\mathbf{z} = \frac{1}{2}\begin{bmatrix}106 \\ 133 \\ 83 \\ 186 \\ 177 \\ 149\end{bmatrix}= \begin{bmatrix}53.0 \\ 66.5 \\ 41.5 \\ 93.0 \\ 88.5 \\ 74.5\end{bmatrix}
$$
</div>
7. If the students took a third exam, and the scores for the same six students were presented in vector **w**, how would you write the algebraic expression (using vector notation) to obtain the students' mean scores for all three exams?
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_07');">Show/Hide Solution</button>
<div id="solution_07" style="display:none; margin: -40px 0 40px 40px;">
$$
\frac{1}{3}(\mathbf{x} + \mathbf{y} + \mathbf{w})
$$
</div>
8. If the mean score on Exam 3 was 60, write the algebraic expression (using vector notation) to find the six students' mean deviation scores on Exam 3.
<button class="solution-btn solution-btn-default" onclick="toggle_visibility('solution_08');">Show/Hide Solution</button>
<div id="solution_08" style="display:none; margin: -40px 0 40px 40px;">
$$
\mathbf{w} - \begin{bmatrix}60 \\ 60 \\ 60 \\ 60 \\ 60 \\ 60\end{bmatrix}
$$
</div>
:::
<br />