<< LinearAlgebra`MatrixManipulation`

example 7.14   p.170

kk = 
        EI/L^3 {{12, 6  L, -12, 6 L}, {6 L, 4 L^2, -6 L, 
              2 L^2}, {-12, -6 L, 12, -6 L}, {6 L, 
              2 L^2, -6 L, 4 L^2}};
MatrixForm[kk]

parameter set

tabEI = {Sqrt[2]^4, Sqrt[1/2]^4} EI
tabL = {1/2, 1/2} L
ne = Length[tabEI]

para[k_] := {EI ->  tabEI[[k]], 
        L ->  tabL[[k]]}

stiffness matrix fromulation

FemK := {kkt = ZeroMatrix[2 ne + 2]; 
          Do[{ns = 2 (k - 1) + 1; 
              Do[kkt[[ns + i, ns + j]] = 
                  kkt[[ns + i, ns + j]] + (kk[[i + 1, j + 1]] /. 
                        para[k]), {i, 0, 3}, {j, 0, 3}]}, {k, 
              ne}]}[[1]]

FemK
MatrixForm[kkt]

xt = {0, 0, δ2, θ2, 
        0, θ3}
ft = {-r1, -m1, P, 0, -r3, 0}

ans = Solve[
          kkt . xt == ft, {δ2, θ2, θ3, r1, m1, 
            r3}][[1]]

draw deflection curves

para1 = {EI ->  1, L ->  1, P ->  1}

def[k_, x0_, 
        xe_] := {tti = {{1, 0, -(3/(L^2)), (2/(L^3))}, {0, 
                1, -(2/L), (1/(L^2))}, {0, 0, 
                (3/(L^2)), -(2/(L^3))}, {0, 0, -(1/L), (1/(L^2))}} /. 
            para[k]; 
        xx = Take[xt /. ans, {2 (k - 1) + 1, 2 (k - 1) + 4}]; 
        yx = xx . tti . {1, x, x^2, x^3} /. para1; 
        Plot[-yx 1000 /. x ->  t - x0, {t, x0, xe}, 
          GridLines ->  Automatic, AspectRatio ->  0.3, 
          PlotRange ->  {{0, 1}, {-10, 0}}, 
          PlotStyle ->  Hue[0.9]]}

Show[def[1, 0, 0.5], def[2, 0.5, 1]]