Solutions to the first Test
(c) Copyright 1997 by Evans M. Harrell II
     All rights reserved.
We begin with some definitions from the Mathematica  notebooks included in the text:
Projf[f_,g_, {x_,a_,b_}] := g Integrate[(f g /. x -> intvar), {intvar,a,b}] \
                             / Integrate[(g^2 /. x -> intvar), {intvar,a,b}]
TrigId = {Cos[Pi n_] -> (-1)^n, Sin[Pi n_] -> 0};
 1.  The goal of this problem is to approximate the function  1-x^2 on the interval -1 < x < 1
by a piecewise linear function (i.e., a function whose graph consist of straight-line segments).

  Let
	f_0(x) = 1
	f_1(x) = |x|
	f_2(x) = |2/3 - |x-1/3| |
	f_3(x) = |2/3 - |x+1/3| |

a) Construct an orthonormal set of functions on the interval  
-1 < x < 1, the span of which is the same as the span of  
{f_0, ..., f_3}.
We begin with f_0, which just needs to be scaled by a constant to be normalized:
g0[x_] := 1/Sqrt[2]
The next step is to orthogonalize f_1 to the constant, i.e., subtract off its average:
      |x| - 1/2
      
The norm of this is:
Sqrt[2 Integrate[(x - 1/2)^2, {x,0,1}]]
   1
-------
Sqrt[6]
In order to avoid explicit absolute-value functions, let's define:
g1[x_] := Sqrt[6] (x - 1/2)  /; 0 <= x <= 1
g1[x_] := Sqrt[6] (-x - 1/2) /; -1 <= x < 0
Next we orthogonalize f_2 to these two functions, but the task is simplified when we note that 
<g1,f2> = 0 already.  Thus we need only subtract the average from f_2 to get a function orthogonal to g0 and g1:   |2/3 - |x-1/3| | - 1/2.  This needs to be normalized, and its norm turns out to be
Sqrt[6* Integrate[x^2, {x,0,1/3}]]
     2
Sqrt[-]
     3
-------
   3
g2[x_] := (3^(3/2)/Sqrt[2]) (-x -2/3) /; -1 <= x < -1/3
g2[x_] := (3^(3/2)/Sqrt[2])  x      /; -1/3 <= x < 1/3
g2[x_] := (3^(3/2)/Sqrt[2]) (-x +2/3) /;  1/3 <= x <= 1
The function f3(x) turns out not to be linearly independent of g0 and g2, so when we orthogonalize it to the previous functions, we get 0.  Conclusion:  

										There is no g3.
 b) Find the function f(x) in the span of these functions, which is
closest in the r.m.s. sense to the function 1-x^2 on the interval 
-1 < x < 1.
The function 1-x^2 is even and g2 is odd, so the only contributions are from g0 and g1.  
Because of the absolute values, it is better to use the fact that functions are even in order to calculate this on the positive interval 0 <= x <= 1:
BestApprox[x_] := Projf[(1-x^2), 1, {x,0,1}]  \
           + Projf[(1-x^2), x - 1/2, {x, 0, 1}]
BestApprox[x]
7
- - x
6
Because the result has to be even, we see that the asctual best approximation we want is:

			        7/6 - |x|    .
 c)  What is the r.m.s. distance from  1-x^2  to this approximation?  Provide a specific number.
Again, it is convenient to do the integrals on 0 < x < 1 and use the observation that the functions we use are even.:
RMS = Sqrt[2 * Integrate[(1 - x^2 - (7/6 - x))^2, {x,0,1}]]
    1
----------
3 Sqrt[10]
 2.  Calculating a Fourier series
 a)  Find the (full) Fourier series for the following function on the interval -1 < x < 1.
Find the formula for all coefficients, and be explicit about how they show up in the series.

	f(x) =   x^2 - 1, when -1 < x < 0;

		     =  1 - x^2, when 0 ≤ x ≤ 1
We first notice that f[x] is odd.  All the cosine coefficients (the a's) are 0:
 
           A0 = 0, Am = 0, all m.

For the b coefficients, we can use the symmetry to do all integrals on the interval 0 < x < 1:
FourierB[x_, n_] = 2 (2/2) Integrate[(1-x^2) Sin[2 Pi n x/2], {x,0,1}] /. TrigId
          n         2   2
   -2 (-1)    -2 - n  Pi
2 (-------- - -----------)
     3   3       3   3
    n  Pi       n  Pi
 b) Sketch the sum of the Fourier series of part a) on the interval -2 < x < 2.
According to the powerful theorem, the Fourier series will conferge to the function, except where it has discontinuities, including the end-points.   At discontinuities, it confverges to the average.

For the b coefficients, we can use the symmetry to do all integrals on the interval 0 < x < 1:
SumF[x_] := x^2 - 1 /; -1 < x < 0
SumF[x_] := 1 - x^2 /; 0 < x < 1
SumF[x_] := (x-2)^2 - 1 /; 1 < x < 2
SumF[x_] := 1 - (x+2)^2 /; -2 < x < -1
SumF[x_] := 0 /; x = 0
SumF[x_] := 0 /; x = -1
SumF[x_] := 0 /; x = 1
SumF[x_] := 0 /; x = -2
SumF[x_] := 0 /; x = 2
Plot[SumF[x], {x,-2,2}]
 3.  It is shown in the text that the function 
     f(x) = x - 1/2, 0 < x < 1, has the Fourier series
       - Sum[(1/n Pi) Sin[2 n Pi x], {n, 1, infinity}]
 a)  Use this information to evaluate 
	Sum[(1/n^2), {n, 1, infinity}]
This is a problem about the Parseval formula, which says in this case that 
       ||f||^2 = (1/2) Sum[ b_n ^2]
Taking into account the factor of pi, this implies that the sum in question equals
In[1]:=
2 Pi^2 Integrate[(x - 1/2)^2, {x,0,1}]
Out[1]=
  2
Pi
---
 6
 b)  Use this information to estimate the r.m.s. error in approximating the function  f(x) = x - 1/2 by the first three terms in its Fourier series. 
Again, we use the Parseval formula, to get 
Sqrt[1/12 - (1/2) Sum[1/(n Pi)^2, {n,1,3}]]
N[%]
     1      49
Sqrt[-- - ------]
     12        2
          72 Pi
0.119911
 4.  An equation for a 2-vector
 a)   Consider the equation for a 2-vector v
Solve[{{1,2},{1,2}}.{a,b} == {1,1}, {a,b}]
Solve::svars: 
   Warning: Equations may not give solutions for all
     "solve" variables.
{{a -> 1 - 2 b}}
 b)   Find the specific solution which is closest to the vector {1,1}:
DistSquared[b_] = (1 - 2 b - 1)^2 + (b - 1)^2
        2      2
(-1 + b)  + 4 b
Now minimize this with methods of Calc I:
D[%, b]
2 (-1 + b) + 8 b
Solve[% == 0, b]
       1
{{b -> -}}
       5
Vec = {1 - 2/5, 1/5}
 3  1
{-, -}
 5  5