You are on page 1of 5

# 8/16/13 5:03 AM

H:\lab2.m

1 of 2

%%AML 705 FEM LAB SHEET 2 QUESTION 1 %% SUBMITTED BY MANU.C(2012AME2625),VIKAS DWIVEDI(2012AME2624) %% For solving 1d deformation of a bar loaded by point forces

clear all clc format compact % compact view in the command window %input finp=fopen('AB.txt','r'); %opens input file E=fscanf(finp,'%e',1); %input Young's modulus L=fscanf(finp,'%e',1);%input length A=fscanf(finp,'%e',1);%C.S area of the bar present case being constant area ne=fscanf(finp,'%e',1);%input number of finite elements being considered ele_con(:,1)=fscanf(finp,'%e',ne);%ele_con being the matrix containing the details of the nodes of elements being connected ele_con(:,2)=fscanf(finp,'%e',ne); %% %element level requirements n=ne+1; % no. of nodes a=L/ne;% length of each element k= element(E,A,a); %% global stiffness matrix using ele_con K=zeros(n,n); %K is symmetric,banded,nxn for 1d bar problem with the order of connectivity being considered for i=1:ne for j=1:2 for z=1:2 l=ele_con(i,j); r=ele_con(i,z); %loop to obtain Global stiffness matrix from local stiffnes matrix as per the connectivity constraints K(l,r)=K(l,r)+k(j,z); end end end disp('Global stifness Matrix'); K %% %Force matrix tot_F=zeros(n,1);%intialisation global force matrix fnn=fscanf(finp,'%e',1);%total no of nodes being subjected to forces for i =1:fnn fn(i)=fscanf(finp,'%e',1);%vector of nodes being subjected to forces end tot_F(fn)=fscanf(finp','%e',fnn); %% %displacement matrix

8/16/13 5:03 AM

H:\lab2.m

2 of 2

u=zeros(n,1);%initialisation of global diplacement matrix unn=fscanf(finp,'%e',1);%total no of nodes with given displacement for i =1:unn ebc_node(i)=fscanf(finp,'%e',1);%vector of nodes with given displacement end u(ebc_node,1)=fscanf(finp,'%e',unn); %% %Processing and output activeDof=setdiff([1:n]',[ebc_node]); %nodes with unknown displacement for j=1:length(ebc_node) tot_F(1:n)=tot_F(1:n)-K(:,ebc_node(j)).*u(ebc_node(j)) %force matrix manupulation with 'ku' components known end disp=K(activeDof,activeDof)\tot_F(activeDof); %calculation unknown displacements displ_new=zeros(n,1); displ_new(activeDof)=disp; F=K*displ_new; reactions=F(ebc_node); jj=1:n; fprintf('displacement each node in mm\n ' ) fprintf('%e \n ',displ_new) fprintf('forces at each node in N \n ' ) fprintf('%f \n ',F) fout1=fopen('displacement_force.dat','wt'); for i=1:n fprintf(fout1,'%15.6e',displ_new(i)); fprintf(fout1,'\n'); end fprintf(fout1,'\n'); for i=1:n fprintf(fout1,'%15.6e',F (i)); fprintf(fout1,'\n'); end fprintf(fout1,'\n'); fclose(finp); fclose(fout1); %%

8/16/13 5:03 AM

H:\element.m

1 of 1

## 2e5 800 300 4 1 2 3 4 2 3 4 5 1 5 3000 1 1 0

AB

Page 1

0.000000e+000 1.000000e-002 2.000000e-002 3.000000e-002 4.000000e-002 -3.000000e+003 0.000000e+000 -1.818989e-012 0.000000e+000 3.000000e+003

displacement_force

Page 1