Cs = {A1, A3, A5}; 
    n = Length[Cs];
v = 
      Sum[Cs[[i]] Sin[(2  i - 1) Pi x/L], {i, n}]; 
    v2 = D[v, {x, 2}]
W=Integrate[(EI v2^2)/2 - w v, {x, 0, L}]- (P v /. x -> (L/2))

grad = Table[D[W, Cs[[i]]], {i, n}];
vsol = 
      v /. Solve[grad == 0, Cs][[1]]
vsol2 = D[vsol, {x, 2}]

grad1 = 
      Table[Integrate[
            EI v2 D[v2, Cs[[i]]] - w D[v, Cs[[i]]], {x, 0, 
              L}] - (P D[v, Cs[[i]]] /. x -> (L/2)), {i, 
          n}]
vsol1 = v /. Solve[grad1 == 0, Cs][[1]]