kill(   
    all   
);

l : a-h;

I declare two auxiliary functions for linear interpolation along a segment

note: the evalution of the RHS of := is suspended (not performed) at define/assigment time; the suspended evaluation is performed in addition to the usual ones at call time

N1(xi) := 1-xi;

the define function, instead, evaluates as usual its second argument, then it assigns it to the first (which is NEVER evaluated, since object of further assigment, this is an exception of the general rule)

define(
    N2(goofy),
    goofy
);

define(
    mylinearinterpolationonBC(s),
    factor( vBp*N1(s/l)+vCm*N2(s/l) )
);

I initialize the strain energy as a null term

U:0$

Components of internal action along the AB segment, in-plane components alone

M1Ap:0*P+0*YA+0*XA-1*PsiA+0*F $

M1Bm:0*P+0*YA+h*XA-1*PsiA+0*F $

define(
    M1AB(s),
    expand(M1Ap*N1(s/h)+M1Bm*N2(s/h))
);

U : U + integrate( M1AB(s)^2/2/E/J , s , 0 , h );

BC segment

M1Bp:M1Bm $

M1Cm:0*P+0*YA+a*XA-1*PsiA-l*F $

define(
    M1BC(s),
    expand(M1Bp*N1(s/l)+M1Cm*N2(s/l))
);

U : U + integrate( M1BC(s)^2/2/E/J , s , 0 , l );

CD segment

M1Cp:M1Cm $

M1Dm:0*P-b*YA+a*XA-1*PsiA-l*F $

define(
    M1CD(s),
    expand(M1Cp*N1(s/b)+M1Dm*N2(s/b))
);

U : U + integrate( M1CD(s)^2/2/E/J , s , 0 , b );

DE segment

M1Dp:M1Dm $

M1Em:+a*P-b*YA+0*XA-1*PsiA+h*F $

define(
    M1DE(s),
    expand(M1Dp*N1(s/l)+M1Em*N2(s/l))
);

U : U + integrate( M1DE(s)^2/2/E/J , s , 0 , a );

U$
ratsimp(%)$
factor(%);

I proceed evaluating the partial derivatives of the strain energy with respect to the applied gen. loads in order to obtain the associated gen. displacements

diff(U,F)$
ratsimp(%)$
utB:%$

diff(U,P)$
ratsimp(%)$
utC:%$

diff(U,XA)$
ratsimp(%)$
uA:%$

diff(U,YA)$
ratsimp(%)$
vA:%$

diff(U,PsiA)$
ratsimp(%)$
psiA:%$