%%%%%%%%%%%%%%%%%% Main function %%%%%%%%%%%%%%%%%%%%%%%%
function [v,D]=fem4buck(typ)
% declaring global variable to be accessible for all fuctions
global elem node KG KSig idofgivendof
% defining element data structure and node data structure
elem=struct('end1',1,'end2',2,'E',1,'A',1,'I',1);
node=struct('x',0,'y',0,'u',[],'v',[],'th',[]);

%%%%%%%%%%%%%%%%%%%% Pre-processing %%%%%%%%%%%%%%%%%%%%
% The following functions recieve the required data from the user
buckcol;
columnbuckling;

%%%%%%%%%%%%%%% Solution phase %%%%%%%%%%%%%%%%%%%
KG(idofgivendof,:)=[];
KG(:,idofgivendof)=[];
KSig(idofgivendof,:)=[];
KSig(:,idofgivendof)=[];
[v,D]=eigs(KG,KSig,1,'sm');
%%%%%%%%%%%%%%% Post Processing %%%%%%%%%%%%%%
switch typ
    case 1
        v=[0;v(2:3:end)];
    case 2
        v=[0;v(3:3:end-1);0];
end
v=v/max(abs(v));