Example 2
 Approximate the solution of -y¢¢+ 2y = x, 0 £ x £ 1, and y(0) = y(1) = 0. 
Using x0 = 0, x1 = 0.2, x2 = 0.4, x3 = 0.6, x4 = 0.8, and x5 = 1

Analysis: The equation is the same as in Example 1. But this time we divide the interval into 5 subintervals. 
So we have p(x) = 1, q(x) = 2, and f(x) = x. Since n is one less than the number of subintervals n = 4.

We have five subintervals [0, 0.2], [0.2, 0.4], [0.4, 0.6], [0.6, 0.8], [0.8, 1] and the length of subintervals are the same, namely 
h0 = h1 = h2 = h3 = h4 = 0.2. 
With n = 4, we have four base functions

f1(x) =  ì
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
î
x
0.2
,     0 < x £ 0.2
0.4-x
0.2
,     0.2 < x £ 0.4
0,           0.4 £ x £ 1
f2(x) =  ì
ï
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
ï
î
0,           0 £ x £ 0.2
x-0.2
0.2
,     0.2 < x £ 0.4
0.6-x
0.2
,     0.4 < x £ 0.6
0     0.6 < x £ 1
,
f3(x) =  ì
ï
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
ï
î
0,     0 < x £ 0.4
x-.04
0.2
,     0.4 < x £ 0.6
0.8-x
0.2
,     0.6 < x £ 0.8
0,           0.8 £ x £ 1
and
f4(x) =  ì
ï
ï
ï
ï
ï
í
ï
ï
ï
ï
ï
î
0,           0 £ x £ 0.6
x-0.6
0.2
,     0.6 < x £ 0.8
1-x
0.2
,     0.8 < x £ 1
.

Our approximation to the solution will be u(x) = c1f1(x) + c2f2(x)+ c3f3(x)+ c4f4(x), 
where c1, c2, c3, and c4 are the unknown parameters that are obtained by minimizing the functional

I[f] = I[c1f1(x) + c2f2(x)+ c3f3(x)+ c4f4(x)]
with
I[f]= ó
õ
1

0

[c1f1¢(x) +c2f2¢(x) +c3f3¢(x)+c4f4¢(x)]2 + 2[c1f1(x)  c2f2(x)+c3f3(x)+c4f4(x)]2 - 2x(c1f1(x) +c2f2(x) +c3f3(x)+c4f4(x))}dx
.

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

æ
ç
ç
ç
ç
ç
ç
è
a11     a12     a13     a14
a21     a22     a23     a24
a31     a32     a33     a34
a41     a42     a43     a44
ö
÷
÷
÷
÷
÷
÷
ø
æ
ç
ç
ç
ç
è
c1
c2
c3
c4
ö
÷
÷
÷
÷
ø
æ
ç
ç
ç
ç
è
b1
b2
b3
b4
ö
÷
÷
÷
÷
ø
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 ó
õ
x2

x1

(x - x1)2q(x) dx + ( 1
h2
)2 ó
õ
x3

x2

(x3 - x)2q(x) dx
a33
ó
õ
1

0

{p(x)[f3¢(x)]2 + q(x)[f3(x)]2} dx
( 1
h2
)2 ó
õ
x3

x2

p(x) dx + ( 1
h3
)2 ó
õ
x4

x3

p(x) dx
    + ( 1
h2
)2 ó
õ
x3

x2

(x - x2)2q(x) dx + ( 1
h3
)2 ó
õ
x4

x3

(x4 - x)2q(x) dx
a44
ó
õ
1

0

{p(x)[f4¢(x)]2 + q(x)[f4(x)]2} dx
( 1
h3
)2 ó
õ
x4

x3

p(x) dx + ( 1
h4
)2 ó
õ
x5

x4

p(x) dx
    + ( 1
h3
)2 ó
õ
x4

x3

(x - x3)2q(x) dx + ( 1
h4
)2 ó
õ
x5

x4

(x5 - 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 
a23
a32
ó
õ
1

0

{p(x)f2¢(x)f3¢(x) + q(x)f2(x)f3(x)} dx
-( 1
h2
)2 ó
õ
x3

x2

p(x) dx + ( 1
h2
)2 ó
õ
x3

x2

(x3 - x)(x - x2)q(x) dx 
a34
a43
ó
õ
1

0

{p(x)f3¢(x)f4¢(x) + q(x)f3(x)f4(x)} dx
-( 1
h3
)2 ó
õ
x4

x3

p(x) dx + ( 1
h3
)2 ó
õ
x4

x3

(x4 - x)(x - x3)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
b3
ó
õ
1

0

f(x)f3(x) dx
1
h2
ó
õ
x3

x2

(x - x2) f(x) dx+  1
h3
ó
õ
x4

x3

(x4 - x) f(x) dx
and
b4
ó
õ
1

0

f(x)f4(x) dx
1
h3
ó
õ
x4

x3

(x - x3) f(x) dx+  1
h4
ó
õ
x5

x4

(x5 - 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.)

We can get the linear system for c as

æ
ç
ç
ç
ç
è
6.3 
-2.36667
-2.36667 
6.3
-4.93333
0
0
-4.93333 
0
10.2667 
-4.93333
-4.93333 
10.2667
ö
÷
÷
÷
÷
ø
æ
ç
ç
ç
ç
è
c1
c2
c3
c4
ö
÷
÷
÷
÷
ø
æ
ç
ç
ç
ç
è
0.116667
0.233333
0.12
0.16
ö
÷
÷
÷
÷
ø

And the solution is c = (0.0260791, 0.0461646, 0.053777, 0.0414253). 
Therefore we obtain the approximate solution.
Hence the approximate solution is:
u(x) = 0.0260791f1(x) + 0.0461646f2(x)
+0.053777f3(x) + 0.0414253f4(x)

Click For Mathematica Definition of f1(x) , f2(x), f3(x), f4(x), 
Click Here For Computation of aij