
clear all
clc

NodeNum=xlsread('Truss2D-Input.xlsx','General','C2')
ElemNum=xlsread('Truss2D-Input.xlsx','General','C4')
PrescDOFNum=xlsread('Truss2D-Input.xlsx','General','C6')

NodeCoord=xlsread('Truss2D-Input.xlsx','NodeCoord')
ElemConec=xlsread('Truss2D-Input.xlsx','ElemConec')
ElemProp=xlsread('Truss2D-Input.xlsx','ElemProp')
PrescDOF=xlsread('Truss2D-Input.xlsx','BoundaryConditions')
Force=xlsread('Truss2D-Input.xlsx','ExternalForces')

% Computing The Length and Angle of Each Element
for i=1:ElemNum
    DeltaX=NodeCoord(ElemConec(i,2),1)-NodeCoord(ElemConec(i,1),1);
    DeltaY=NodeCoord(ElemConec(i,2),2)-NodeCoord(ElemConec(i,1),2);
    ElemLeng(i)=sqrt(DeltaX^2+DeltaY^2);
    ElemAngl(i)=atan(DeltaY/DeltaX);
end

% Computing Ttal Stiffness Matrix, Using the 'StiffnessMat' Function
Kmat=StiffnessMat(NodeNum,ElemNum,ElemProp,ElemLeng,ElemAngl,ElemConec)

% Computing Modified Stiffness Matrix
KmatMod=Kmat
for i=1:PrescDOFNum
    KmatMod(PrescDOF(i,1),:)=0;
    KmatMod(:,PrescDOF(i,1))=0;
    KmatMod(PrescDOF(i,1),PrescDOF(i,1))=1;
end

% Computing Modified Forces Vector
for i=1:NodeNum
    ForceVec(i)=Force(i,1);
    ForceVec(2*i)=Force(i,2);
end
ForceMod=ForceVec'
for i=1:PrescDOFNum
    ForceMod=ForceMod-Kmat(:,PrescDOF(i,1))*PrescDOF(i,2);
end
for i=1:PrescDOFNum
    ForceMod()=ForceMod-Kmat(:,PrescDOF(i,1))*PrescDOF(i,2);
end

ForceMod