Fixes to Ritz Method

Clear["Global`*"]; Off[General::spell, General::spell1];

Define basis functions

ϕ[
        i_, Δx_] :=  ((x - Δx (i - 
                      1))/Δ)x 
          UnitStep[
            x - Δx (i - 
                    1)] UnitStep[Δx i  -  
              x] +  (((Δx (i + 1)  -  
                  x))/Δ)x 
          UnitStep[
            x - Δx i]  UnitStep[Δx (i + 
                    1)  -  x]
ϕk[n_, L_]  :=  Table[ϕ[i, L/n], {i, 0, n}]

Plot some to get a feeling of what they look like

n = 2;  L = 6;
Plot[Evaluate[ϕk[n, L]], {x, 0, L*1.5}];

Note an interesting property of these functions

Plot[Sum[ϕk[2, 6][[i]], {i, 3}] // Simplify, {x, 0, 6}, 
        PlotRange -> {0, 1.4}, 
        PlotStyle -> {Thickness[0.008], 
            RGBColor[1, 0, 0]}];

One of the great values of this kind of functions is interpolation. Define a function we want to interpolate

f[x_] :=Sin[x]- 0.5 Sin[2 x] + 0.3 Sin[3x]- 0.7 Sin[5.5x]
v[n_,L_] := Table[f[L/n i],{i,n}]

f[x_]  := 
      Cos[x] - 0.5 Sin[2 x] + 0.3 Sin[3 x] - 
        0.7 Sin[5.5 x]

Define a set of "n+1" discrete values

Vk[n_, L_]  :=  Table[f[L/n i], {i, 0, n}]

Create the interpolation function as:

fint[n_, L_]  :=  Vk[n, L] . ϕk[n, L]

Plot the function and its interpolant

L = 5;  n  =  10; 
    Plot[{f[x], fint[n, L]}, {x, 0, L}, 
      PlotStyle ->  {{Thickness[0.008], 
            RGBColor[1, 0, 0]}, {Thickness[0.008]}}];

Forget the interpolation problem and let's look at an approximation for the solution of our aerospace structures:

Uk[n_]  :=  Table[uk[i], {i, 0, n}]
U[n_, L_]  :=  ϕk[n, L] . Uk[n] // Simplify

U[2, 1] // Simplify

Define the approximate potential Π(Ck) for this problem (or try)

In this case we need to do a good job at computing the derivatives of the basis functions

dϕdx[
        n_, Δx_]  :=  (1/Δ)x 
          UnitStep[
            x - Δx (i - 
                    1)] UnitStep[Δx i  -  
              x] +  ((-1)/Δ)x 
          UnitStep[
            x - Δx i]  UnitStep[Δx (i + 
                    1)  -  x]
dϕkdx[n_, L_]  :=  
      Table[dϕdx[i, L/n], {i, 0, n}]

dUdx[n_, L_]  :=  
      Uk[n] . dϕkdx[n, L]  // 
        Simplify
(Subscript[U, tip])[n_, L_]  :=  
      U[n, L]  /.  
        x  ->  
          L
q  =  ρg;
A[x_]  :=  
      (Subscript[A, 0]) (2 - (x/( L)))
Π[n_, L_] :=(∫_0^L)( ((EE A[x])/2) (dUdx[n, L])^2 - 
                  U[n, L] q) \[DifferentialD]x - P (Subscript[U, tip])[n, L] // 
        Expand
Π[1, 1]

dudx  =  
      Integrate[(((dUdx[1, 10]))^2), {x, 0, 10}] // Expand

eq  =  Table[D[dudx, uk[i]], {i, 0, 1}]

Solve[eq == 0, Uk[1]]