You are on page 1of 3

% MATLAB codes for Finite Element Analysis

% problem9a.m
% antonio ferreira 2008
% clear memory
clear all
clc

% E; modulus of elasticity
% I: second moment of area
% L: length of bar
E=1e6;
L=10;
t=L/1000;
I=1*t^3/12;
EI=E*I;

% generation of coordinates and connectivities


numberElements=3;
nodeCoordinates=linspace(0,L,numberElements+1)';

elementNodes = zeros(numberElements,2);
for i=1:numberElements;
elementNodes(i,1)=i;
elementNodes(i,2)=i+1;
end

numberNodes=size(nodeCoordinates,1);
xx=nodeCoordinates(:,1);

% distributed force
P=-1000;

% for structure:
% displacements: displacement vector
% force : force vector
% stiffness: stiffness matrix

% GDof: global number of degrees of freedom


GDof=2*numberNodes;

%U=zeros(GDof,1);
stiffnessSpring=zeros(GDof+1);
forceSpring=zeros(GDof+1,1);
% Inicializacion de la matriz de rigidez y el vector fuerza
force=zeros(GDof,1);
stiffness=zeros(GDof);

% Generacion de la matriz de rigidez y el vector fuerza


for e=1:numberElements;

% generacion de indices de los grados de libertad de cada elemento en


% el sistema global
indice=elementNodes(e,:); %vector variable de nodos en cada elemento
elementDof=[ 2*(indice(1)-1)+1 2*(indice(2)-1) 2*(indice(2)-1)+1 2*(indice(2)-1)+2];
% vector variable de grados de libertad en cada elemento

% longitud de cada elemento


LElem=xx(indice(2))-xx(indice(1)) ;
ll=LElem;

%matriz de rigidez del elemento


k1=EI/(LElem)^3*[12 6*LElem -12 6*LElem;
6*LElem 4*LElem^2 -6*LElem 2*LElem^2;
-12 -6*LElem 12 -6*LElem ;
6*LElem 2*LElem^2 -6*LElem 4*LElem^2];

%vector fuerza del elemento


f1=[P*LElem/2 P*LElem*LElem/12 P*LElem/2 ...
-P*LElem*LElem/12]';

% ensamble del vector fuerza en el sistema global


force(elementDof)=force(elementDof)+f1;
% ensamble de la matriz de rigidez en el sistema global
stiffness(elementDof,elementDof)=stiffness(elementDof,elementDof)+k1;

end

% spring added
stiffnessSpring(1:GDof,1:GDof)=stiffness;
forceSpring(1:GDof)=force;
k=10;
stiffnessSpring([GDof-1 GDof+1],[GDof-1 GDof+1])=...
stiffnessSpring([GDof-1 GDof+1],[GDof-1 GDof+1])+[k -k;-k k];

% boundary conditions and solution


fixedNodeU =[1]'; fixedNodeV =[2]';
prescribedDof=[fixedNodeU;fixedNodeV;GDof+1];
% solution
activeDof=setdiff([1:(GDof+1)]',[prescribedDof]);
U=stiffnessSpring(activeDof,activeDof)\forceSpring(activeDof);
displacements=zeros(GDof+1,1);
displacements(activeDof)=U;

% displacements
% disp('Displacements')
% jj=1:GDof+1; format
% [jj' displacements]

% drawing deformed shape


U=displacements(1:2:2*numberNodes);

%% Ploteo de la viga
% Create figure
figure1 = figure;

% Create axes
axes1 = axes('Parent',figure1,'FontSize',15);
box(axes1,'on');
hold(axes1,'all');

% Create plot
plot(nodeCoordinates,U,'MarkerSize',15,'Marker','.','LineStyle','none')

% exact solution by Bathe (Solutions Manual of Procedures ...)


load=[L*P/3;L*P/3;L*P/6];
K=E*I/L^3*[189 -108 27;-108 135 -54;27 -54 27+k*L^3/E/I];
X=K\load;

disp('Bathe - extremo derecho de la viga')


X(3)

disp('Resultado')
U(end)

You might also like