u''  +  u  +  x  =  0,  0 < x < 1 
u(
          0)  =  u(1) = 0 

a) Weak form: multiply differential equation by admissible virtual field δu, integrate between (0,1), integrate by parts:
\(TraditionalForm\`0 = \(∫\_0\%1\((u''\  + \ u\  + \ 
                  x)\)\ δu dx\  = 
\(∫\_0\%1\((\(-u'\)\ δu'\  + \ \((u'\ δu)\)'\  + \ 
                    u\ δu\  + \ 
                    x\ δu)\)\ dx\  = 
\ \ u'\ δu\( | \_0\)\^1\(+\(∫\_0\%1\((\(-u'\)\ δu'\ \  + \ 
                        u\ δu\  + \ 
                        x\ δu)\)\ dx\)\)\)\)\)

Admissibility requires the boundary terms to vanish, The weak form is therefore:
(∫_0^1)(-u' δu'   +  
                u δu  +  x δu) dx = 
        0,  ∀  δu s . 
              t .  δu(0)  =  δu(1)  =  0

Approximation:

Φ[n_] := 
      Table[(Subscript[ϕ, i]) =  x (1 - x) (x^(i - 1)), {i, 
          n}]
Ck[n_]  :=  Table [c[i], {i, n}]
(Subscript[U, N])[n_]  :=  Φ[n] . Ck[n]

(Subscript[U, N])[10]

(Subscript[ϕ, 3])

K[n_] :=  
      Table[(∫_0^1)(-(Subscript[ϕ, i]) (Subscript[ϕ, j])  +  (∂_x) (Subscript[ϕ, i]) (∂_x) (Subscript[ϕ, j])) \[DifferentialD]x, {i, 
          n}, {j, n}]
R[n_]  :=  
      Table[(∫_0^1) x (Subscript[ϕ, i]) \[DifferentialD]x,  {i, 
          n}]

sol[n_]  :=  Inverse[K[n]] . R[n]

sol[4] // N

uh[n_] :=  sol[n] . Φ[n]

uh[1]

u  =  Sin[x]/Sin[1] - x

n = 1;
up  =  uh[n];
Plot[{u, up}, {x, 0, 1},  
      PlotStyle -> {Thickness[0.01], {Thickness[0.01], 
            Dashing[{0.05, 0.025}], 
            RGBColor[1, 0, 0]}}]
n = 2;
up  =  uh[n];
Plot[{u, up}, {x, 0, 1},  
      PlotStyle -> {Thickness[0.015], {Thickness[0.02], 
            Dashing[{0.05, 0.05}], RGBColor[1, 0, 0]}}]