Clear the memory in order to have the subsequent code running in a clean environment.

kill(
    all
);

Calculate reaction forces at supports A and B

rotAeq : - F*a + YB*(a+b)=0;

ideally,
":"( rotAeq , - F*a + YB*(a+b)=0 );

vteq : +YA+YB-F=0;

rotAeq;

sols : linsolve( [rotAeq , vteq] , [YA,YB] );

[YA,YB] : ev([YA,YB] , sols);

now I can write the bending moments

MfAC:YA*sAC;

MfBC:YB*sBC;

bending moment at the loaded cross section

ev(MfAC,sAC=a);

ev(MfBC,sBC=b);

Strain energy lineic density (strain energy density per unit length)

[uAC,uBC] : 1/2*[MfAC,MfBC]^2/E/J;

in the above, I tried to type as less as possible still preserving readability

Strain energy for the structure

UAC : integrate( uAC , sAC , 0 , a );

UBC : integrate( uBC , sBC , 0 , b );

U :  factor(
        ratsimp( 
            UAC + UBC 
        )
);

by resorting to the 2nd Castigliano theorem, we evaluate
the shaft deflection at the "F" loaded cross section

f : diff( U , F , 1 );

if we also need the peak value of (flexural) stress along the shaft, then

MfMAX: ev(MfAC,sAC=a)  ;

flexural strenght modulus for the cross section

W : %pi*d^3/32 ;

peak stress value

sigma : MfMAX/W;