%---------------------
%     PROGRAM Wire.m
%---------------------

  clear
% ---------------------
%     INPUT DATA
% ---------------------
  load MSHDAT   -ASCII
  load NODES    -ASCII

  TENS  = MSHDAT(1);
  NUMEL = MSHDAT(2);

  NUMNP=NUMEL+1;
% -----------------------
% Declare sparse matrix
% -----------------------
  SK=sparse(NUMNP,NUMNP);

  for  I=1:NUMNP
     XORD(I)=NODES(I,1);
     NPBC(I)=NODES(I,2);
     U(I)   =NODES(I,3);
     F(I,1)   =NODES(I,4);
  end

% ----------------------------- 
% FORMATION OF STIFFNESS MATRIX
% ----------------------------- 
  Se=[1,-1; ...
     -1, 1];              % Element Stiffness template
  for I=1:NUMEL;
     NP=[I,I+1];           % Element's nodes
     RL=XORD(I+1)-XORD(I);
     RK=TENS/RL;
     SK(NP,NP)=SK(NP,NP)+RK*Se;
  end;

% -------------------- 
% BOUNDARY CONDITIONS
% -------------------- 
  for I=1:NUMNP;
     if NPBC(I) == 1;
        SK(I,I)=SK(I,I)*1.0E+05; 
        F(I,1)=U(I)*SK(I,I); 
     end;
  end;

% ------------------------------ 
% Solve equations
% ------------------------------ 
  U =  SK\F;

% -----------
% OUTPUT DATA
% -----------
  save XORD XORD -ASCII
  save U U -ASCII

  plot(XORD,U)
  grid
  xlabel('Distance along wire')
  ylabel('Deflection of wire')
  title(['Deflection of a tightly'...
         ' stretched wire'])


