> restart;

> with(linalg):

projections - 6.2)12 and 6.1)32.

6.2) 12.

> a1:=vector([1,-1,1,0,0]);

> a2:=vector([-1,0,0,0,1]);

> a3:=vector([0,0,1,0,1]);

> a4:=vector([1,0,0,1,1]);

We check to see if {a1,a2,a3,a4} is a linearly independent set, by setting them as rows of a matrix, row reducing to see if we get a pivot in each row.

> A:=matrix([a1,a2,a3,a4]);

> gausselim(A);

So the answer is YES, the set {a1,a2,a3,a4} IS a linearly independent set.

Now we proceed with Gram-Schmidt to get an orthonormal set of vectors which span the same subspace as {a1,a2,a3,a4}.

We start by finding an orthogonal set {v1,v2,v3,v4} which spans the same space as {a1,a2,a3,a4}

> v1:= matrix([a1]);

> v2:= evalm(matrix([a2]) - (dotprod(a2,a1)/dotprod(a1,a1))* v1);

> vect2:=vector([-2/3,-1/3,1/3,0,1]);

The dot products involved in the next computation are:

> dotprod(a3,a1);

> dotprod(a1,a1);

> dotprod(a3,vect2);

> dotprod(vect2,vect2);

> v3:=evalm(matrix([a3]) - (dotprod(a3,vect2)/dotprod(vect2,vect2))*v2 - (dotprod(a3,a1)/dotprod(a1,a1))*v1);

> vect3:=vector([1/5,3/5,2/5,0,1/5]);

> v4:=evalm(matrix([a4]) - (dotprod(a4,vect3)/dotprod(vect3,vect3))*v3 -(dotprod(a4,vect2)/dotprod(vect2,vect2))*v2 - (dotprod(a4,a1)/dotprod(a1,a1))*v1);

> vect4:=vector([2/3,0,-2/3,1,2/3]);

Now we can normalize the vectors {v1,v2,v3,v4} to get {q1,q2,q3,q4}.

> q1:= evalm( (1/sqrt(dotprod(a1,a1)))*v1);

> q2:= evalm( (1/sqrt(dotprod(vect2,vect2)))*v2);

> q3:= evalm( (1/sqrt(dotprod(vect3,vect3)))*v3);

> q4:= evalm( (1/sqrt(dotprod(vect4,vect4)))*v4);

6.1) 32.

We want to find the distance from the tip of a=[2,-1,3] to the subspace W=sp([1,2,4]).

For this we need to express a as the sum of its projection in W and its projection in W perp.

W perp is the nullspace of the matrix with 1 row: a.

> a:=vector([2,-1,3]);

> A:=matrix([[1,2,4]]);

> zero:=vector([0]);

> linsolve(A,zero);

So we see there are two basis vectors, [-2,1,0] and [-4,0,1] to W perp.

We now want to express a as r1 [1,2,4] + r2 [-2,1,0] + r3 [-4,0,1].

> B:= matrix([[1,-2,-4],[2,1,0],[4,0,1]]);

For this, we solve the system B r = a

> linsolve(B,a);

The projection of a on W perp is then

> awp:= evalm( (-15/7)*matrix([[-2,1,0]]) + (5/7)* matrix([[-4,0,1]]) );

> vecawp:=vector([10/7,-15/7,5/7]);

The final answer to this problem is the magnitude of awp.

> ans:= evalm ( sqrt (dotprod (vecawp,vecawp)));

>