% Script to compute internal loads
% in a truss structure for given applied loads.
% The user is queried for input to describe the loading
%
%  N     number of bays
%  a     length of longerons
%  b     length of battens
%  theta interior angle in y-z triangles
%
 N = 13; a = 4; b = 4; theta = pi/3;
 [D , nodes, links] = truss_load(N, a, b, theta); 
 show_truss(nodes,links)
% 
while 1 > 0
   app_node = input(...
 [' At which node is the load applied [4, 5,...',int2str(3*(N+1)), '] ? \n '] ...
                    )
   if app_node >= 4 & app_node <= 3*(N+1)
       break
   end
end
%
while 1 > 0
   app_dir = input([' In which direction is the load applied [1, 2 3] ? \n '])
   if app_dir >= 1 & app_dir <= 3
       break
   end
end
%
v = zeros(9*N,1);
v((app_node-4)*3 + app_dir) = 1.; % unit load at app_node in app_dir
%
truss_loads = -D\v;
%
[val, loc] = max(abs(truss_loads));
disp(['The maximum load is ',num2str(val),' and occurs in link ',int2str(loc)])
if N < 4
    disp(['Loads in the links '])
    disp(reshape(truss_loads,3,3*N))
end