SOLUTION: Find the scalar and vector projection of the vector b=⟨−1,5,−2⟩ onto the vector a=⟨1,4,2⟩.

Algebra ->  Vectors -> SOLUTION: Find the scalar and vector projection of the vector b=⟨−1,5,−2⟩ onto the vector a=⟨1,4,2⟩.       Log On


   



Question 1160831: Find the scalar and vector projection of the vector b=⟨−1,5,−2⟩ onto the vector a=⟨1,4,2⟩.
Answer by CPhill(2303) About Me  (Show Source):
You can put this solution on YOUR website!
```python
import numpy as np
a = np.array([1, 4, 2])
b = np.array([-1, 5, -2])
dot_ab = np.dot(a, b)
norm_a = np.linalg.norm(a)
norm_a_sq = np.dot(a, a)
comp_ab = dot_ab / norm_a
proj_ab = (dot_ab / norm_a_sq) * a
print(f"a . b = {dot_ab}")
print(f"|a|^2 = {norm_a_sq}")
print(f"|a| = sqrt({norm_a_sq}) = {np.sqrt(norm_a_sq)}")
print(f"Scalar projection: {dot_ab} / sqrt({norm_a_sq}) = {comp_ab}")
print(f"Vector projection: ({dot_ab}/{norm_a_sq}) * {a} = {proj_ab}")

```
```text
a . b = 15
|a|^2 = 21
|a| = sqrt(21) = 4.58257569495584
Scalar projection: 15 / sqrt(21) = 3.2732683535398857
Vector projection: (15/21) * [1 4 2] = [0.71428571 2.85714286 1.42857143]

```
To find the scalar and vector projections of $\mathbf{b} = \langle -1, 5, -2 \rangle$ onto $\mathbf{a} = \langle 1, 4, 2 \rangle$:
---
### Step 1: Compute the Necessary Magnitudes and Dot Product
1. **Dot product ($\mathbf{a} \cdot \mathbf{b}$):**
$$\mathbf{a} \cdot \mathbf{b} = (1)(-1) + (4)(5) + (2)(-2) = -1 + 20 - 4 = 15$$

2. **Magnitude squared ($\Vert{}\mathbf{a}\Vert{}^2$):**
$$\Vert{}\mathbf{a}\Vert{}^2 = 1^2 + 4^2 + 2^2 = 1 + 16 + 4 = 21$$

3. **Magnitude ($\Vert{}\mathbf{a}\Vert{}$):**
$$\Vert{}\mathbf{a}\Vert{} = \sqrt{21}$$


---
### Step 2: Scalar Projection ($\text{comp}_{\mathbf{a}}\mathbf{b}$)
The scalar projection is the component of $\mathbf{b}$ in the direction of $\mathbf{a}$:
$$\text{comp}_{\mathbf{a}}\mathbf{b} = \frac{\mathbf{a} \cdot \mathbf{b}}{\Vert{}\mathbf{a}\Vert{}} = \frac{15}{\sqrt{21}} = \frac{5\sqrt{21}}{7}$$
---
### Step 3: Vector Projection ($\text{proj}_{\mathbf{a}}\mathbf{b}$)
The vector projection scales the unit vector in the direction of $\mathbf{a}$ by the scalar projection:
$$\text{proj}_{\mathbf{a}}\mathbf{b} = \left(\frac{\mathbf{a} \cdot \mathbf{b}}{\Vert{}\mathbf{a}\Vert{}^2}\right)\mathbf{a} = \frac{15}{21}\langle 1, 4, 2 \rangle = \frac{5}{7}\langle 1, 4, 2 \rangle$$
$$\text{proj}_{\mathbf{a}}\mathbf{b} = \left\langle \frac{5}{7}, \frac{20}{7}, \frac{10}{7} \right\rangle$$
---
### Summary of Results
* **Scalar projection:** $\dfrac{15}{\sqrt{21}}$ (or $\dfrac{5\sqrt{21}}{7}$)
* **Vector projection:** $\left\langle \dfrac{5}{7}, \dfrac{20}{7}, \dfrac{10}{7} \right\rangle$