Given differential equation, $ \frac{d^2u}{dx^2} + u = x^2 $ where $ 0 \leq x \leq 1 $ with boundary condition u = 0 at x = 0; $\frac{du}{dx}$ = 1 at x = 1
Approximate solution is given by,
$ u = C_0 + C_1x + C_2x^2 + C_3x^3 $ ......(1)
Imposing boundary condition
i) At x = 0, u = 0
$\therefore 0 = C_0 + 0 \\
\therefore C_0 = 0 \\
\therefore u = C_1x + C_2x^2 + C_3x^3 $
Differentiating the above equation, we get,
$ \frac{du}{dx} = C_1 + 2C_2x + 3C_3x^2 $
ii) At x = 1, $\frac{du}{dx}$ = 1
$ \therefore 1 = C_1 + 2C_2 + 3C_3 \\
\therefore C_1 = 1 - 2C_2 - 3C_3 $
Substituting the values of $C_0$ and $C_1$ in equation 1, we get,
$ u = (1-2C_2-3C_3)x + C_2x^2 + C_3x^3 \\
\therefore u = C_2(x^2-2x) + C_3(x^3-3x) + x $
To find Residual Function,
$\frac{d^2u}{dx^2} + u - x^2 = R $ .......(2)
$\because u = C_2(x^2-2x) + C_3(x^3-3x) + x $
Differentiating the above equation, we get,
$\frac{du}{dx} = 2C_2(x-1) + 3C_3(x^2-1) $
Again differentiating the above equation, we get,
$\frac{d^2u}{dx^2} = 2C_2 + 6xC_3 $
Equation (2) becomes,
$ [2C_2 + 6C_3] + [C_2(x^2-2x) + C_3(x^3-3x) + x] - x^2 = R \\
\therefore C_2(x^2-2x+2) + C_3(x^3-3x+6x) + x - x^2 = R \\
\therefore C_2(x^2-2x+2) + C_3(x^3+3x) + x - x^2 = R $
Galerkin Method, weighted integral form,
$\int_0^1 w_iR \,\, dx = 0 \\
\int_0^1 w_i [C_2(x^2-2x+2) + C_3(x^3+3x) + x - x^2] \,\, dx = 0 $
For Galerkin, $w_i$ = coefficient of constant in u.
For i = 1, $w_i = x^2-2x$, we get,
$\int_0^1 [x^2-2x][C_2(x^2-2x+2) + C_3(x^3+3x) + x - x^2] \,\, dx = 0 \\
\therefore C_2 \int_0^1 (x^2-2x)(x^2-2x+2) \,\, dx + C_3 \int_0^1 (x^2-2x)(x^3+3x) \,\, dx + \int_0^1 (x^2-2x)(x - x^2) \,\, dx = 0 \\
\therefore -0.8C_2 - 1.4833C_3 - 0.1167 = 0 \\
\therefore -0.8C_2 - 1.4833C_3 = 0.1167 ..........(A) $
For i = 2, $w_2 = x^3 - 3x $
$ C_2 \int_0^1 (x^3 - 3x)(x^2-2x+2) \,\, dx + C_3 \int_0^1 (x^3 - 3x)(x^3+3x) \,\, dx + \int_0^1 (x^3 - 3x)(x - x^2) \,\, dx = 0 \\
-1.4833C_2 - 2.8571C_3 - 0.2167 = 0 \\
i.e.
-1.4833C_2 - 2.8571C_3 = 0.2167 ......(B)$
Solving (A) and (B), we get,
$ C_2 = -0.14; C_3 = -0.00303 $
Approximate solution is given by,
$ u = -0.14(x^2-2x) - 0.00303(x^3-3x) + x $
At x = 0.3, u = 0.37405
At x = 0.6, u = 0.7224