1. Find an orthogonal basis of the subspace of C[0,1] spanned by the functions sin(x), cos(x), x.

For simplicity's sake, we can begin by denoting our subspace as V. Thus, from what was given in the problem, we can say that V is spanned by sin(x), cos(x), and x. Now, we can prove that sin(x), cos(x), and x are linearly independent by looking at the Wronskian (the matrix of vector A, with it's first and second derivatives) and seeing that the determinant of it is not identicaly zero.

> with(linalg):A:=vector([sin(x),cos(x),x]);
A := sin(x) cos(x) x
> W:=Wronskian(A,x);
W := [ sin(x) cos(x) x ]
[ cos(x) -sin(x) 1 ]
[ -sin(x) -cos(x) 0 ]
> det(W);


- cos(x)2 x - x sin(x)2


Since the determinant of the Wronskian is not identically zero, we know that the functions are linearly independent. We also know that we have a basis

{sin(x), cos(x), x} of V.


We will now use the Gram-Schmidt process to find an orthogonal basis of V.

We begin with our first vector as sin(x).

> v_1:=sin(x);

v1 := sin(x)


Then the second vector is cos(x)-( <cos(x),sin(x)>/<sin(x),sin(x)> ) * sin(x). If we recall, the dot product of two functions from C[0,1] is the integral of their products on the range [0,1]:

> v_2:=cos(x)-int(sin(x)*cos(x),x=0..1)/int(sin(x)^2,x=0..1) * sin(x);
                                                 2
                                           sin(1)  sin(x)
                 v2 := cos(x) - 1/2 -------------------------
                                     - 1/2 sin(1) cos(1) + 1/2
The third vector is x-<x,v1>/<v1,v1>*v1-<x,v2>/<v2,v2>*v2:

> v_3:=x-int(x*v1,x=0..1)/int(v1^2,x=0..1)*v1-int(x*v_2,x=0..1)/ int(v_2^2,x=0..1)*v_2;

           (sin(1) - cos(1)) sin(x)
v3 := x - ------------------------ -
                - 1/2 %1 + 1/2

 /      2                                  3    \ /                   
2       \
 |cos(1)  sin(1) - cos(1) - sin(1) + sin(1)     | |             sin(1)  
sin(x)|
 |------------------------------------------ - 1| |cos(x) - 1/2 
--------------|
 \                  %1 - 1                      / \             - 1/2 %1 
+ 1/2/
 ------------------------------------------------------------------------------
                              4         2       2             2
                        sin(1)  + sin(1)  cos(1)  + 1   sin(1)
                  - 1/2 ----------------------------- + -------
                                    %1 - 1               %1 - 1

%1 :=                           sin(1) cos(1)
===============================================================
Problem 2

2. Find the distance from the function ex to the subspace spanned by the functions sin(x), cos(x), x in C[0,1].

This distance vector is found by taking the vector and subtracting from this its projection on the subspace. The projection is found by taking <ex,v1>/<v1,v1>*v1 + <ex,v2>/<v2,v2>*v2 + <ex,v3>/<v3,v3>*v3.

> proj:=int(E^x*v_1,x=0..1)/int(v_1^2,x=0..1)*v_1 + int(E^x*v_2,x=0..1)/int(v_2^2,x=0..1)*v_2 + int(E^x*v_3,x=0..1)/int(v_3^2,x=0..1)*v_3;
        (- 1/2 exp(1) cos(1) + 1/2 exp(1) sin(1) + 1/2) sin(x)
proj := ------------------------------------------------------ + (1/4 exp(1)
                            - 1/2 %1 + 1/2

 (2 cos(1) sin(2) - sin(1) - 5 cos(1) + 2 sin(1) sin(2) + cos(3) - sin(3))/

                                         /                   2       \
                    sin(2) - 3 + cos(2)  |             sin(1)  sin(x)|
 (sin(2) - 2) - 1/2 -------------------) |cos(x) - 1/2 --------------|
                         sin(2) - 2      \             - 1/2 %1 + 1/2/

      /            4                  2\
    / |      sin(1)  + %2 + 1   sin(1) |
   /  |- 1/2 ---------------- + -------| + (- 1/2 (- 9 + 2 sin(1) + 10 cos(1)
  /   \           %1 - 1         %1 - 1/

                                   2           2
  + cos(3) sin(2) + 2 cos(1) sin(2)  + 2 sin(2)  - sin(4) - sin(3) sin(2)

                                     2
  + 6 sin(2) cos(2) + 2 sin(1) sin(2)  - 2 cos(3) + 4 sin(2) - 8 cos(2)

  - 9 cos(1) sin(2) - 5 sin(1) sin(2) + 2 sin(3) + cos(4)) exp(1)/

                                                                2
 ((1 + cos(2)) (sin(2) - 2)) + (4 + 2 sin(1) - 7 cos(1) + sin(2)

  + 2 sin(2) cos(2) - 2 cos(1) cos(2) + 2 sin(1) cos(2) + cos(3) - 4 sin(2)

  - 4 cos(2) + 2 cos(1) sin(2))/((1 + cos(2)) (sin(2) - 2))) (x

    (sin(1) - cos(1)) sin(x)
  - ------------------------ -
         - 1/2 %1 + 1/2

 /      2                                  3    \ /                   
2       \
 |cos(1)  sin(1) - cos(1) - sin(1) + sin(1)     | |             sin(1)  
sin(x)|
 |------------------------------------------ - 1| |cos(x) - 1/2 
--------------|
 \                  %1 - 1                      / \             - 1/2 %1 
+ 1/2/
 ------------------------------------------------------------------------------
                                    4                  2
                              sin(1)  + %2 + 1   sin(1)
                        - 1/2 ---------------- + -------
                                   %1 - 1         %1 - 1

     /                      2       3            4       3            6
 )  /  (1/3 (- 7 - 12 sin(1)  cos(1)  + 12 cos(1)  sin(1)  + 12 sin(1)  
cos(1)
   /

             4       3            5                   4       2
  + 24 sin(1)  cos(1)  + 18 sin(1)  cos(1) + 36 cos(1)  sin(1)

            7                   2       5                   4
  + 8 sin(1)  cos(1) + 12 sin(1)  cos(1)  - 36 cos(1) sin(1)

             8                   6       2            5       
3            2
  + 12 sin(1)  cos(1) - 68 sin(1)  cos(1)  - 28 sin(1)  cos(1)  + 16 sin(1)

             5       3             4       2            7       3
  - 36 cos(1)  sin(1)  + 100 sin(1)  cos(1)  + 14 sin(1)  cos(1)

          9                   2            2                   4       4
  + sin(1)  cos(1) + 12 cos(1)  + 36 sin(1)  cos(1) - 55 sin(1)  cos(1)

                     6       3            5       5            7       2
  + 13 %1 + 24 sin(1)  cos(1)  + 25 sin(1)  cos(1)  - 12 sin(1)  cos(1)

             5       4            2                   5       
4            3
  - 24 sin(1)  cos(1)  - 12 cos(1)  sin(1) + 12 cos(1)  sin(1)  + 12 sin(1)

             3                   4                   3            3
  - 12 cos(1)  sin(1) - 12 cos(1)  sin(1) + 12 cos(1)  - 16 sin(1)  cos(1)

             3       2            5                   
4                    7
  - 36 sin(1)  cos(1)  + 12 cos(1)  sin(1) - 60 sin(1)  - 74 %2 - 12 sin(1)

             8            6            4            7       3
  - 25 sin(1)  + 64 sin(1)  - 12 cos(1)  + 12 cos(1)  sin(1)

             6       2            3       3            6       3
  - 12 cos(1)  sin(1)  + 74 sin(1)  cos(1)  - 12 cos(1)  sin(1) )

    /         4                    2 2                              
2       3
   /  ((sin(1)  + %2 + 1 - 2 sin(1) )  (%1 - 1)) - 4 (- 1 + 3 sin(1)  cos(1)
  /

            4       3           5       2           5                
4       2
  - 3 cos(1)  sin(1)  - 4 sin(1)  cos(1)  + 2 sin(1)  cos(1) - cos(1)  sin(1)

          7                       4         8                  6       2
  + sin(1)  cos(1) + cos(1) sin(1)  + sin(1)  cos(1) - 5 sin(1)  cos(1)

            5       3                      2         5       3
  + 2 sin(1)  cos(1)  + 2 cos(1) + 2 sin(1)  + cos(1)  sin(1)

            4       2         2           2                  4       4
  + 5 sin(1)  cos(1)  - cos(1)  - 2 sin(1)  cos(1) - 3 sin(1)  cos(1)  + 
2 %1

            6       3           2                5       4         3
  + 2 sin(1)  cos(1)  - 3 cos(1)  sin(1) + cos(1)  sin(1)  + sin(1)

          3                  3                  3       2           4
  + cos(1)  sin(1) - 3 sin(1)  cos(1) + 2 sin(1)  cos(1)  - 5 sin(1)  - 2 %2

          7           8           6           3       3
  - sin(1)  - 2 sin(1)  + 5 sin(1)  + 2 sin(1)  cos(1) )

    /         4                    2 2
   /  ((sin(1)  + %2 + 1 - 2 sin(1) )  (%1 - 1)))
  /

%1 :=                           sin(1) cos(1)

                                     2       2
%2 :=                          sin(1)  cos(1)

Whew! Try doing _that_ by hand...
Lets see what that is numerically:
> evalf(proj);

- 5.224647002 sin(x) + .9661885243 cos(x) + 6.613896434 x


Now thats a little bit better! So the distance vector is then

> u:=E^x-evalf(proj);

u := Ex + 5.224647002 sin(x) - .9661885243 cos(x) - 6.613896434 x


We can find the length of this vector by using the definition of the norm of a vector: sqrt(<u,u>)

> sqrt(int(u^2,x=0..1));

.01060787443


So this is the distance!