[Mathematical knowledge] Inner product of vector and base, Matlab code verification

serial number content
1 [Mathematical knowledge] Coordinate base representation of vectors, Matlab code verification
2 [Mathematical knowledge] Inner product of vector and base, Matlab code verification

1. Inner product of vector and basis

Suppose there is a vector a ⃗ \vec{a} in a two-dimensional planea , which is in the coordinate base e ⃗ 1 , e ⃗ 2 \vec{e}_1, \vec{e}_2e 1,e 2The coordinate value below is [ xy ] \left[\begin{matrix}x \\ y \end{matrix}\right][xy]

Let’s first look at the vector a ⃗ \vec{a}a Self and coordinate base e ⃗ 1 \vec{e}_1e 1The inner product of. For the principle of inner product, please refer to the article [Mathematical Knowledge] Vector multiplication, inner product, outer product, matlab code implementation . Here we directly use its conclusion, that is, the inner product of a vector is, the projected length of one vector in the direction of another vector, multiplied by the length of the projected vector, as shown in the figure below

Insert image description here

Described by the formula as

a ⃗ ⋅ e ⃗ 1 = ∥ a ⃗ ∥ ∥ e ⃗ 1 ∥ cos ⁡ ( θ ) \vec{a} \cdot \vec{e}_1 = \|\vec{a}\| \|\vec{e}_1\| \cos(\theta)a e 1=a ∥∥e 1cos ( θ )

In our case, the projected vector is the basis vector e ⃗ 1 \vec{e}_1e 1, and the basis vector e ⃗ 1 \vec{e}_1e 1Its module length ∥ e ⃗ 1 ∥ \|\vec{e}_1\|e 1 is 1 1again1 , therefore

a ⃗ ⋅ e ⃗ 1 = ∥ a ⃗ ∥ ∥ e ⃗ 1 ∥ cos ⁡ ( θ ) = ∥ a ⃗ ∥ cos ⁡ ( θ ) \begin{align} \vec{a} \cdot \vec{e}_1 & = \|\vec{a}\| \|\vec{e}_1\| \cos(\theta) \\ &= \|\vec{a}\| \cos(\theta)\end{aligned}a e 1=a ∥∥e 1cos ( θ )=a cos ( θ ).

Numerically ∥ a ⃗ ∥ cos ⁡ ( θ ) \|\vec{a}\| \cos(\theta)a cos ( θ ) is equal to the vectora ⃗ \vec{a}a In the coordinate base e ⃗ 1 \vec{e}_1e 1coordinate values ​​on. If the coordinate base e ⃗ 1 \vec{e}_1e 1We think of it as the abscissa, then a ⃗ ⋅ e ⃗ 1 \vec{a} \cdot \vec{e}_1a e 1Numerically it is equal to the value of the abscissa, that is

a x = a ⃗ ⋅ e ⃗ 1 \begin{aligned} a_x &= \vec{a} \cdot \vec{e}_1 \end{aligned} ax=a e 1

In the same way, we can also get a ⃗ ⋅ e ⃗ 2 \vec{a} \cdot \vec{e}_2a e 2Numerically equal to the value of the ordinate.

a y = a ⃗ ⋅ e ⃗ 2 \begin{aligned} a_y &= \vec{a} \cdot \vec{e}_2 \end{aligned} ay=a e 2

Finally, the formulaic description conclusion is

a x = a ⃗ ⋅ e ⃗ 1 = [ a x a y ] ⋅ [ e 11 e 12 ] = a x e 11 + a y e 12 a y = a ⃗ ⋅ e ⃗ 2 = [ a x a y ] ⋅ [ e 21 e 22 ] = a x e 21 + a y e 22 , ∥ e ⃗ 1 ∥ = ∥ e ⃗ 2 ∥ = 1 \begin{aligned} a_x &= \vec{a} \cdot \vec{e}_1 =\left[\begin{matrix} a_x \\ a_y \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{11} \\ e_{12} \\ \end{matrix}\right] =a_x e_{11} + a_y e_{12} \\ a_y &= \vec{a} \cdot \vec{e}_2 =\left[\begin{matrix} a_x \\ a_y \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{21} \\ e_{22} \\ \end{matrix}\right] =a_x e_{21} + a_y e_{22} \end{aligned},\quad \|\vec{e}_1\| = \|\vec{e}_2\| = 1 axay=a e 1=[axay][e11e12]=axe11+aye12=a e 2=[axay][e21e22]=axe21+aye22,e 1=e 2=1


2. Example of two-dimensional plane vector

The following is an example based on a vector on a two-dimensional plane.

Suppose there is a two-dimensional plane vector a ⃗ \vec{a} as mentioned abovea , in the standard coordinate base e ⃗ 1 = [ 1 0 ] , e ⃗ 2 = [ 0 1 ] \vec{e}_1=\left[\begin{matrix} 1 \\ 0 \\ \end{matrix}\right ], \vec{e}_2=\left[\begin{matrix} 0 \\ 1 \\ \end{matrix}\right]e 1=[10],e 2=[01] The coordinate value under is[ axay ] = [ 3 4 ] \left[\begin{matrix}a_x \\ a_y \end{matrix}\right] = \left[\begin{matrix}3 \\ 4 \end{ matrix}\right][axay]=[34]

Now, we change the coordinate base to e ⃗ 1 ′ = [ 1 2 1 2 ] , e ⃗ 2 ′ = [ − 1 2 1 2 ] \vec{e}_{1^\prime}=\left[\begin{ matrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \\ \end{matrix}\right], \vec{e}_{2^\prime }=\left[\begin{matrix} -\frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \\ \end{matrix}\right]e 1=[2 12 1],e 2=[2 12 1] , the coordinate value under this new basis is[ ax ′ ay ′ ] = [ 7 2 1 2 ] \left[\begin{matrix}a_{x^\prime} \\ a_{y^\prime} \end{ matrix}\right] = \left[\begin{matrix} \frac{7}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \end{matrix}\right][axay]=[2 72 1]

Verify the conclusion first

a x = a ⃗ ⋅ e ⃗ 1 = [ a x a y ] ⋅ [ e 11 e 12 ] = a x e 11 + a y e 12 = [ 3 4 ] ⋅ [ 1 0 ] = 3 × 1 + 4 × 0 = 3 \begin{aligned} a_x &= \vec{a} \cdot \vec{e}_1 =\left[\begin{matrix} a_x \\ a_y \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{11} \\ e_{12} \\ \end{matrix}\right] =a_x e_{11} + a_y e_{12} \\ &= \left[\begin{matrix} 3 \\ 4 \\ \end{matrix}\right] \cdot \left[\begin{matrix} 1 \\ 0 \\ \end{matrix}\right] = 3 \times 1 + 4 \times 0 = 3 \end{aligned} ax=a e 1=[axay][e11e12]=axe11+aye12=[34][10]=3×1+4×0=3

a x ′ = a ⃗ ⋅ e ⃗ 1 ′ = [ a x a y ] ⋅ [ e 1 1 ′ e 1 2 ′ ] = a x e 1 1 ′ + a y e 1 2 ′ = [ 3 4 ] ⋅ [ 1 2 1 2 ] = 3 × 1 2 + 4 × 1 2 = 7 2 \begin{aligned} a_{x^\prime} &= \vec{a} \cdot \vec{e}_{1^\prime} =\left[\begin{matrix} a_{x} \\ a_{y} \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{11^\prime} \\ e_{12^\prime} \\ \end{matrix}\right] =a_{x} e_{11^\prime} + a_{y} e_{12^\prime} \\ &= \left[\begin{matrix} 3 \\ 4 \\ \end{matrix}\right] \cdot \left[\begin{matrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \\ \end{matrix}\right] = 3 \times \frac{1}{\sqrt{2}} + 4 \times \frac{1}{\sqrt{2}} = \frac{7}{\sqrt{2}} \end{aligned} ax=a e 1=[axay][e11e12]=axe11+aye12=[34][2 12 1]=3×2 1+4×2 1=2 7

By observing the figure below, we can also roughly see the vector a ⃗ \vec{a}a In the new basis e ⃗ 1 ′ \vec{e}_{1^\prime}e 1The projection length on is 7 / 2 7/\sqrt{2}7/2

Please add image description

This is also consistent with the effect in the coordinate chart.

Continue below to verify the conclusion

a y = a ⃗ ⋅ e ⃗ 2 = [ a x a y ] ⋅ [ e 21 e 22 ] = a x e 21 + a y e 22 = [ 3 4 ] ⋅ [ 0 1 ] = 3 × 0 + 4 × 1 = 4 \begin{aligned} a_y &= \vec{a} \cdot \vec{e}_2 =\left[\begin{matrix} a_x \\ a_y \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{21} \\ e_{22} \\ \end{matrix}\right] =a_x e_{21} + a_y e_{22} \\ &= \left[\begin{matrix} 3 \\ 4 \\ \end{matrix}\right] \cdot \left[\begin{matrix} 0 \\ 1 \\ \end{matrix}\right] = 3 \times 0 + 4 \times 1 = 4 \end{aligned} ay=a e 2=[axay][e21e22]=axe21+aye22=[34][01]=3×0+4×1=4

a y ′ = a ⃗ ⋅ e ⃗ 2 ′ = [ a x a y ] ⋅ [ e 1 1 ′ e 1 2 ′ ] = a x e 1 1 ′ + a y e 1 2 ′ = [ 3 4 ] ⋅ [ − 1 2 1 2 ] = 3 × ( − 1 2 ) + 4 × 1 2 = 1 2 \begin{aligned} a_{y^\prime} &= \vec{a} \cdot \vec{e}_{2^\prime} =\left[\begin{matrix} a_{x} \\ a_{y} \\ \end{matrix}\right] \cdot \left[\begin{matrix} e_{11^\prime} \\ e_{12^\prime} \\ \end{matrix}\right] =a_{x} e_{11^\prime} + a_{y} e_{12^\prime} \\ &= \left[\begin{matrix} 3 \\ 4 \\ \end{matrix}\right] \cdot \left[\begin{matrix} -\frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \\ \end{matrix}\right] = 3 \times (-\frac{1}{\sqrt{2}}) + 4 \times \frac{1}{\sqrt{2}} = \frac{1}{\sqrt{2}} \end{aligned} ay=a e 2=[axay][e11e12]=axe11+aye12=[34][2 12 1]=3×(2 1)+4×2 1=2 1

The second conclusion also means that the vector a ⃗ \vec{a}a In the new basis e ⃗ 2 ′ \vec{e}_{2^\prime}e 2The projection length on is 1 / 2 1/\sqrt{2}1/2


3. Code verification

a_x = 3;
a_y = 4;
a = [a_x
     a_y];

e_1 = [ 1
        0];
e_2 = [ 0
        1];

e_1_prime = [ sqrt(2)/2
              sqrt(2)/2];
e_2_prime = [-sqrt(2)/2
              sqrt(2)/2];
>> dot(a, e_1)
ans =
     3

>> dot(a, e_2)
ans =
     4

>> dot(a, e_1_prime)
ans =
    4.9497

>> dot(a, e_2_prime)
ans =
    0.7071

Ref


Guess you like

Origin blog.csdn.net/weixin_36815313/article/details/132310270