 Example 1
Approximate the solution of -y¢¢+ 2y = x, 0 £ x £ 1, and y(0) = y(1) = 0. Using x0 = 0, x1 = 0.3, x2 = 0.7, x3 = 1.

Analysis: To apply the method we need first to indentify p(x), q(x), and f(x). The next thing we need to do is find out the n, the number of base functions and the base functions themselves. In the case of piecewise base functions, n is one less than the number of subinterval [0, 1] is divided into. Here in this example, n = 2 since we have three subintervals [0, 0.3], [0.3, 0.7], [0.7, 1] and the length of subintervals are h0 = 0.3, h1 = 0.4, and h2 = 0.3. With n = 2, we have two base functions

f1(x) =  ì
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
î
 x 0.3 ,     0 < x £ 0.3
 0.7-x 0.4 ,     0.3 < x £ 0.7
 0,           0.7 £ x £ 1 and

f2(x) =  ì
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
î
 0,           0 £ x £ 0.3
 x-0.3 0.4 ,     0.3 < x £ 0.7
 1-x 0.3 ,     0.7 < x £ 1 Our approximation to the solution will be u(x) = c1f1(x) + c2f2(x), where c1 and c2 are the unknown parameter that are obtained by minimizing the functional

 I[f] = I[c1f1(x) + c2f2(x)]
among all possible values for c1, and c2 . Here,
 I[f] = ó õ 1 0 {[c1f1¢(x) + c2f2¢(x)]2 + 2[c1f1(x) + c2f2(x)]2 - 2x(c1f1(x) + c2f2(x))} dx
.

From theoritical analysis, we know c = (c1, c2) is the solution of the linear system

æ
ç
è
 a11
 a12
 a21
 a22
ö
÷
ø
æ
ç
è
 c1
 c2
ö
÷
ø
æ
ç
è
 b1
 b2
ö
÷
ø
here
 a11
 =
 ó õ 1 0 {p(x)[f1¢(x)]2 + q(x)[f1(x)]2} dx
 =
 ( 1 h0 )2 ó õ x1 x0 p(x) dx + ( 1 h1 )2 ó õ x2 x1 p(x) dx
 + ( 1 h0 )2 ó õ x1 x0 (x - x0)2q(x) dx + ( 1 h1 )2 ó õ x2 x1 (x2 - x)2q(x) dx
 a22
 =
 ó õ 1 0 {p(x)[f2¢(x)]2 + q(x)[f2(x)]2} dx
 =
 ( 1 h1 )2 ó õ x2 x1 p(x) dx + ( 1 h2 )2 ó õ x3 x2 p(x) dx
 + ( 1 h1 )2 ó õ x1 x1 (x - x1)2q(x) dx + ( 1 h2 )2 ó õ x3 x2 (x3 - x)2q(x) dx
 a12
 =
 a21
 =
 ó õ 1 0 {p(x)f1¢(x)f2¢(x) + q(x)f1(x)f2(x)} dx
 =
 -( 1 h1 )2 ó õ x2 x1 p(x) dx + ( 1 h1 )2 ó õ x2 x1 (x2 - x)(x - x1)q(x) dx
 b1
 =
 ó õ 1 0 f(x)f1(x) dx
 =
 1 h0 ó õ x1 x0 (x - x0) f(x) dx+ 1 h1 ó õ x2 x1 (x2 - x) f(x) dx

and

 b2
 =
 ó õ 1 0 f(x)f2(x) dx
 =
 1 h1 ó õ x2 x1 (x - x1) f(x) dx+ 1 h2 ó õ x3 x2 (x3 - x) f(x) dx

Plug in the definetion for p(x) = 1, q(x) = 2, and f(x) = x, one easily find the integration.

(Noticed that, for any a, b, c we have

 ó õ b a p(x) dx = ó õ b a (-1) dx = a - b
and
 ó õ b a (x - c)2 q(x) dx = ó õ b a 2 (x - c)2 = 2 3 [ (b-c)3 - (a- c)3]
and the power rule
 ó õ b a xk dx = 1 k (bk+1 - ak+1)
will help to find all the integrations.)
 a11
 =
 6.3
 a22
 =
 6.3
 a12
 =
 a21 = -2.36667
 b1
 =
 0.116667
 b2
 =
 0.233333

So our linear system for c is

æ
ç
è
 6.3
 -2.36667
 -2.36667
 6.3
ö
÷
ø
æ
ç
è
 c1
 c2
ö
÷
ø
æ
ç
è
 0.116667
 0.233333
ö
÷
ø

Solution is c = (0.0377608, 0.0512223), so we get approximation

 u(x) = 0.0377608f1(x) + 0.0512223f2(x) The graph of  reals solution is 