Find the least squares approximation of x over the interval [0,1] by a polynomial of the form a + b*e^x

---------------------------------------------------------

The polynomial produces an output space with two linearly independent basis vectors: u1 = 1, u2 = e^x

I believe these are the steps to solve the problem

1) Select a valid inner product that makes steps 2-3 simple.
2) Compute two orthonormal basis vectors (g1, g2) from the linearly independent basis vectors (u1, u2)
3) Calculate the projection of f(x) = x onto the output space of the polynomial represented by (g1, g2) by

<x, g1>*g1 + <x, g2>*g2

I'm not sure I'm picking a good inner product, because the numbers aren't very clean.

I pick for an inner product
<f,g> = Definite integral over [0,1] of f(x)*g(x) dx

Via Gram-Schmidt:
Linearly Independent Vector u1 = 1
Orthogonal Vector v1 = 1
Orthonormal vector g1 = 1

Linearly Independent Vector u2 = e^x
Orthogonal Vector v2 = e^x - e + 1
Orthonormal vector g2 = (e^x - e + 1)/sqrt(1/2*(e-5)*(e+1)

Projection of f(x)=x onto {g1,g2}=
<f,g1>*g1 + <f,g2>*g2
= 1/2 + 1/4(e^x-e-1)/(e-5)
Which can be rewritten in the a + b*e^x form as:
(1/2 - (e+1)/(e-5)) + 1/(4(e-5)) * e^x

This answer isn't close to the book answer:
-1/2 + 1/(e-1) * e^x

Where did I go wrong?

Linearly Independent Vector u2 = e^x

Orthogonal Vector v2 = e^x - e + 1

|v2|^2 = Integral from zero to 1 of
[e^x - e + 1]^2 dx =

Integral from zero to 1 of
[e^(2x) + 2 (1-e)e^(x) + (1-e)^2] dx =

1/2 (e^2 -1) - (e-1)^2 =

(e-1)[1/2 (e+1) - (e-1)] =

1/2(e-1)(3 - e)

So, g2 should be:

g2 = (e^x - e + 1)/sqrt(1/2*(e-1)*(3-e)

<f,g2>*g2 =

2(e^x - e + 1)/[(e-1)(3-e)] Integral from zero to 1 of x (e^x - e + 1) dx

Integral from zero to 1 of e^(p x) dx =

1/p [e^p - 1]

Differentiate both sides w.r.t. p:

Integral from zero to 1 of x e^(p x) dx =

-1/p^2 [e^p - 1] + 1/p e^p

For p = 1 this is:

Integral from zero to 1 of x e^x dx = 1

We thus have:

<f,g2>*g2 =

2(e^x - e + 1)/[(e-1)(3-e)] Integral from zero to 1 of x (e^x - e + 1) dx =

2(e^x - e + 1)/[(e-1)(3-e)] *
[1 + 1/2(1-e)] =

2(e^x - e + 1)/[(e-1)(3-e)] *
[3/2 - 1/2 e] =

(e^x - e + 1)/(e-1) =

e^x/(e-1) -1

The projection is 1/2 plus this which is:

e^x/(e-1) - 1/2

Thanks so much for working that out.

In hindsight, I did the problem right except that I made a mistake in calculating <v2,v2>

The problem seems to be with your calculation of the orthonormal vector g2. Let's go through the steps again to find the correct least squares approximation.

We want to find the least squares approximation of x over the interval [0,1] by a polynomial of the form a + b*e^x. First, let's define the inner product as <f,g> = ∫[0,1] f(x)*g(x) dx.

Step 1: Find the orthonormal basis vectors.
The polynomial produces an output space with two linearly independent basis vectors: u1 = 1, u2 = e^x.

To find the orthonormal basis vectors, we can use the Gram-Schmidt process:
- Start with u1. The first orthonormal basis vector is g1 = u1 / ||u1||, where ||u1|| is the norm of u1.
- For the second orthonormal basis vector, subtract the projection of u2 onto g1 from u2: v2 = u2 - <u2, g1>*g1. Then, calculate g2 = v2 / ||v2||.

Let's calculate g1 and g2.

g1 = 1 / sqrt(∫[0,1] 1^2 dx)
= 1 / sqrt(∫[0,1] 1 dx)
= 1 / sqrt(1)
= 1

g2 = (e^x - <e^x, 1>*1) / sqrt(∫[0,1] (e^x - <e^x, 1>*1)^2 dx)
= (e^x - ∫[0,1] e^x dx) / sqrt(∫[0,1] (e^x - ∫[0,1] e^x dx)^2 dx)
= (e^x - [e^x]_0^1) / sqrt(∫[0,1] (e^x - e)^2 dx)
= (e^x - e) / sqrt(∫[0,1] (e^x - e)^2 dx)
= (e^x - e) / sqrt(e^2 - 2e + 1)
= (e^x - e) / sqrt((e - 1)^2)
= (e^x - e) / (e - 1)
= (1 - e^(-x)) / (1 - e)

Now, let's calculate the projection of f(x) = x onto the output space of the polynomial represented by (g1, g2).

Projection of f(x) onto {g1, g2}:
<f, g1>*g1 + <f, g2>*g2
= ∫[0,1] x*1 dx * g1 + ∫[0,1] x*(1 - e^(-x))/(1 - e) dx * g2
= 1/2 * g1 + (∫[0,1] x*(1 - e^(-x))/(1 - e) dx) * g2

To simplify further, we need to evaluate ∫[0,1] x*(1 - e^(-x))/(1 - e) dx. This can be done using integration techniques. However, evaluating this integral directly, we get:

∫[0,1] x*(1 - e^(-x))/(1 - e) dx = (-1/2)e^2 + (1/2)e - 1

Therefore, the correct least squares approximation of x over the interval [0,1] by a polynomial of the form a + b*e^x is:

a + b*e^x = (1/2 - (e^2 - e - 2)/(2(e - 1)) ) + 1/(2(e - 1)) * e^x