% ============================================================================
% truss.m : Compute internal forces and reactions in cantilever truss structure.
%
% Matrices : Truss     = Represents truss geometry and element connectivity.
%          : Load      = External forces acting on the truss nodes.
%          : Force     = Internal member forces acting in truss elements.
%          : Support   = Relationship between truss and support reactions
%          : Reactions = Matrix of support reaction forces.
% ============================================================================

% Define problem parameters

  NoElmts     = 6;
  NoReactions = 4;

% Setup matrix for "truss connectivity"

  Truss = zeros( NoElmts, NoElmts );
  Truss( 1 , 1 ) =  1;
  Truss( 1 , 2 ) = -1;

  Truss( 2 , 4 ) =  1;

  Truss( 3 , 2 ) =  1;
  Truss( 3 , 3 ) =  1/sqrt(2);

  Truss( 4 , 3 ) =   1/sqrt(2);

  Truss( 5 , 3 ) =   1/sqrt(2);
  Truss( 5 , 5 ) =  -1/sqrt(2);
  Truss( 5 , 6 ) =  -1;

  Truss( 6 , 3 ) =   1/sqrt(2);
  Truss( 6 , 4 ) =   1;
  Truss( 6 , 5 ) =   1/sqrt(2);

% Setup matrix for "external loads" on truss nodes

  Load = zeros( NoElmts, 1 );
  Load( 2 , 1 ) =  10;
  Load( 4 , 1 ) =  10;

% Print matrices for "truss connectivity" and "external loads"

  Truss
  Load

% Solve equations and print "internal member" forces 

  Force = Truss\Load

% Setup matrix for "support reactions" 

  Support = zeros( NoReactions, NoElmts );

  Support( 1 , 1 ) = -1;
  Support( 1 , 5 ) = -1/sqrt(2);
  Support( 2 , 5 ) = -1/sqrt(2);
  Support( 3 , 6 ) = -1;

% Compute and print "support reactions" 

  Reactions = Support*Force

% ============================================================
% the end!
