Axial Rod with distributed force the full explanation of Matlab's implementation with symbolic computing Explanation
Matlab's implementation with 3 elements correction
from wikiversity
MATLAB tutorial on Shape functions
MATLAB tutorial on 2 nodes rod
using direct stiffness method 6 bar truss example
:= Ku=f with K is a stiffness matrix, u vector of displacement, f vector of external force you get u by : inv(K)*f
For student who cannot use Nastran, I'm preparing a Matlab based solution.