# MAT 232 Ch. 4

## Section 4.1

We will talk a lot about vectors.

v = vector([1,2,3])
plot(v)

Here is an example of how to visualize vectors added to other vectors.

var('s,t') @interact def _(V = matrix([,,]), W = matrix([,,]),X = matrix([,,]),show_plane=False ): x = vector([X[0,0],X[1,0],X[2,0]]) v = vector([V[0,0],V[1,0],V[2,0]]) w = vector([W[0,0],W[1,0],W[2,0]]) G = Graphics() G += v.plot(thickness=5) G += w.plot(color='green',thickness=5) for i in [-3..3]: for j in [-3..3]: G += line([(i*v+j*w+x,i*v+j*w+x,i*v+j*w+x),(i*v+(j+1)*w+x,i*v+(j+1)*w+x,i*v+(j+1)*w+x)],alpha=.5,color='red') G += line([(j*v+i*w+x,j*v+i*w+x,j*v+i*w+x),((j+1)*v+i*w+x,(j+1)*v+i*w+x,(j+1)*v+i*w+x)],alpha=.5,color='red') if show_plane: G += parametric_plot3d(s*v+t*w+x,(s,-3,3),(t,-3,3),color='red',alpha=.5) show(G+point([0,0,0],color='purple',size=20)+x.plot(color='purple',thickness=5))

show_plane

## Click to the left again to hide and once more to show the dynamic interactive window

Vectors have norms.

v.norm()
 sqrt(14) sqrt(14)
u = v/v.norm() u.norm()
 1 1

## Section 4.2

Vectors have dot products.

vector([1,2,3]).dot_product(vector([-3,0,1]))
 0 0
vector([1,2,3]) * vector([-3,0,1])
 0 0

Dot product zero means perpendicular ("orthogonal", in general)!

v1 = vector([1,2,3]) v2 = vector([1,1,-1]) v3 = vector([1,0,-1/3]) v4 = vector([0,1,-2/3]) v5 = vector([-2,2,-2/3]) v6 = vector([-1,-2,5/3]) v1.plot()+v2.plot(color='green')+v3.plot(color='green')+v4.plot(color='green')+v5.plot(color='green')+v6.plot(color='green')
v1*v2;v1*v3;v1*v4;v1*v5;v1*v6
 0 0 0 0 0 0 0 0 0 0

There are many ways for things to be orthogonal.  Interestingly, we have some polynomials that are, if you consider the inner product to be $\int_{-1}^1 f(x)g(x)dx$.

for i in range(4): show(expand(legendre_P(i,x)))
 \newcommand{\Bold}{\mathbf{#1}}1 \newcommand{\Bold}{\mathbf{#1}}x \newcommand{\Bold}{\mathbf{#1}}\frac{3}{2} \, x^{2} - \frac{1}{2} \newcommand{\Bold}{\mathbf{#1}}\frac{5}{2} \, x^{3} - \frac{3}{2} \, x
for i in range(4): for j in range(i+1,4): f(x) = legendre_P(i,x) g(x) = legendre_P(j,x) html("$$\int_{-1}^1 \left(%s\\right) \left(%s\\right)\; dx = %s$$"%(latex(f(x)),latex(g(x)),integrate(legendre_P(i,x)*legendre_P(j,x),(x,-1,1))))
 \int_{-1}^1 \left(1\right) \left(x\right)\; dx = 0 \int_{-1}^1 \left(1\right) \left(\frac{3}{2} \, {\left(x - 1\right)}^{2} + 3 \, x - 2\right)\; dx = 0 \int_{-1}^1 \left(1\right) \left(\frac{5}{2} \, {\left(x - 1\right)}^{3} + \frac{15}{2} \, {\left(x - 1\right)}^{2} + 6 \, x - 5\right)\; dx = 0 \int_{-1}^1 \left(x\right) \left(\frac{3}{2} \, {\left(x - 1\right)}^{2} + 3 \, x - 2\right)\; dx = 0 \int_{-1}^1 \left(x\right) \left(\frac{5}{2} \, {\left(x - 1\right)}^{3} + \frac{15}{2} \, {\left(x - 1\right)}^{2} + 6 \, x - 5\right)\; dx = 0 \int_{-1}^1 \left(\frac{3}{2} \, {\left(x - 1\right)}^{2} + 3 \, x - 2\right) \left(\frac{5}{2} \, {\left(x - 1\right)}^{3} + \frac{15}{2} \, {\left(x - 1\right)}^{2} + 6 \, x - 5\right)\; dx = 0

Or you can try some complex vectors.  They multiply differently in the inner product if correctly done, though we won't go that direction.

vector([i,0])*vector([i,0])
 -1 -1
vector([1+i,2]) * vector([1-i,4])
 10 10
vector([1,i]) * vector([1,i])
 0 0
V = vector([1/sqrt(2),i/sqrt(2)])
V.hermitian_inner_product(V)
 1 1

The functions $\sin(kx)$ and $\cos(\ell x)$ are also all orthogonal on $[0,2\pi]$.

@interact def _(i=([1..5]),j=([1..5])): html("The integral $$\int_0^{2\pi} \sin(%s x)\sin(%s x)\; dx$$"%(i,j)) html("is $%s$"%latex(integrate(sin(i*x)*sin(j*x),(x,0,2*pi)))) html("The integral $$\int_0^{2\pi} \cos(%s x)\sin(%s x)\; dx$$"%(i,j)) html("is $%s$"%latex(integrate(cos(i*x)*sin(j*x),(x,0,2*pi))))

## Click to the left again to hide and once more to show the dynamic interactive window

Let's do some orthogonal projection.

@interact def _(V = matrix([[1,7]]),W = matrix([[-4,2]])): V = vector(V.list()) W = vector(W.list()) ProjVW = (V*W)/(W*W)*W OC = V - ProjVW show(plot(ProjVW,color='green',zorder=5)+plot(V,color='green')+plot(W)+line([V.list(),ProjVW.list()],color='black',linestyle='--')+plot(OC,color='black',linestyle='--'),aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

Well, what about in more than two dimensions?

@interact def _(V = matrix([[3,-1,2]]),W = matrix([[1,2,3]])): V = vector(V.list()) W = vector(W.list()) ProjVW = (V*W)/(W*W)*W OC = V - ProjVW show(plot(ProjVW,color='green',zorder=5)+plot(V,color='green')+plot(W)+line([V.list(),ProjVW.list()],color='black',linestyle='--')+plot(OC,color='black',linestyle='--'),aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window