P0(x)=1 P1(x)=x P2(x)=3x2 - 1are orthogonal in the inner product < f, g > := -1S 1 f(x) g(x)dx.
Solution. This requires doing three integrals on the interval [-1,1], and seeing that they are 0.
Problem 2. From first principles (i.e., minimize the error directly; don't just quote the answer), use these polynomials to find the best least-squares fit to exp(-x) on the interval [-1, 1].
Solution. We need to find the coefficients a0, a1, and a2 that minimize the "sum" of squares
E(a0, a1, a2) = -1S 1 (e-x - a0P0(x) - a1 P1(x) - a2P2)2 dx.
Squaring out the integrand, we obtain
E(a0, a1, a2) =
< e-x , e-x >
+ a02< P0 , P0 >
+ a12< P1 , P1 >
+ a22< P2 , P2 >
- 2a0< e-x , P0 >
- 2a1< e-x , P1 >
- 2a2< e-x , P2 >
+ 2a0a1< P0, P1 >
+ 2a0a2< P0, P2 >
+ 2a1a2< P1, P2 >
The last three terms on the right above are zero, by orthogonality. The remaining integrals are straightforward calculations. Carring them all out results in this expression for the error:
E(a0, a1, a2) =
(1/2)(e2 - e-2) + 2a02
+ (2/3)a12 + (8/5)a22
- 2(e - e-1)a0
- 4e-1a1
- 4(e- 7e-1)a2
Minimizing E determines the values of the a's. These values for the a's then give us the least squares fit,
L(x)=(1/2)(e - e-1) P0(x) - 3e-1 P1(x) + (5/4)(e- 7e-1)P2(x).
Using powers of x, this becomes
L(X)= (3/4)(11e-1 - e) - 3e-1x + (15/4)(e-7e-1)x2.
Problem 3. On the same set of axes, sketch exp(-x), the least-squares fit you've found, and the quadratic Taylor polynomial about x=0 for exp(-x).
Solution. The matlab code below generates the plot that follows.
x=-1:0.01:1;
L=(15/4)*(exp(1)-7*exp(-1))*x.^2-3*exp(-1)*x + (33*exp(-1)-3*exp(1))/4;
T=1-x+(1/2)*x.^2;
E=exp(-x);
plot(x,L,':',x,T,'-.',x,E), grid
title('Comparison of Least-Squares Fit and Taylor Polynomial')
legend('Least-squares', 'Taylor','e^{-x}')
xlabel('x')
ylabel('y')
Plot