0% found this document useful (0 votes)
4 views

24_devang_question4_part1

The document contains MATLAB code for calculating the global stiffness matrix, global force matrix, nodal displacements, strain, and stress for a finite element analysis problem. It prompts the user for various input parameters such as the number of elements, length, area, Young's modulus, body force, and point load location. The code also includes interpolation for displacements, strain, and stress at a given point, as well as an analytical solution for comparison.

Uploaded by

nebulaspace3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

24_devang_question4_part1

The document contains MATLAB code for calculating the global stiffness matrix, global force matrix, nodal displacements, strain, and stress for a finite element analysis problem. It prompts the user for various input parameters such as the number of elements, length, area, Young's modulus, body force, and point load location. The code also includes interpolation for displacements, strain, and stress at a given point, as well as an analytical solution for comparison.

Uploaded by

nebulaspace3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

close all;

clear all;
clc;
%this code is for question 4 part 1
noelement=input('input_no of elements: ');
L=input('input_length in mm: ');
A=input('input_area in sq.mm: ');
E=input('input_Youngs modulus: ');
syms x;
nonodes=noelement+1;
nodecoordinates=linspace(0,L,nonodes);
l=nodecoordinates(2)-nodecoordinates(1);
%N-Shape function,B-B matrix
N=[(1-x/l) x/l];
B=diff(N);
%Klocal-Local stiffness matrix
k=[1 -1;-1 1];
Klocal=A*E*k/l;
%Kglobal-Global stiffness matrix
Kglobal=zeros(nonodes);
for i=1:noelement
range=[i i+1];
Kglobal(range,range)=Kglobal(range,range)+Klocal;
end
disp('Global stiffness matrix: ');

Global stiffness matrix:

disp(Kglobal);

33000 -33000
-33000 33000

%Body force matrix calculation


%Fbodyelement=Element body force
a=input('Enter the value of a: ');
q=[a;a];
Fbodyelement=l*q/2;
%point load calculations
Loadlocation=input('Enter the nodal load location: ');
Allloadlnodes=zeros(nonodes,1);
Allloadlnodes(Loadlocation)=input('Enter the point forces: ');

%Fbody- Global force matrix with body forces only


Fbody=zeros(nonodes,1);
for i=1:noelement
range=[i i+1];
Fbody(range,1)=Fbody(range,1)+Fbodyelement;
end
%f-Global force matrix containing both body and point forces
f=Fbody+Allloadlnodes;

1
disp('Global force matrix: ');

Global force matrix:

fprintf('%6.4f\n',double(f));

11.0000
10.0000

%Boundary value calculation


%fixed nodes-Fixed nodal location from user
fixednode=input('Enter the fixed node no: ');
freenodes=setxor(1:nonodes,fixednode);

%Displacement calculation
Kpart=Kglobal(freenodes,freenodes);
Fpart=f(freenodes,1);
disp(Kpart);

33000

Y=inv(Kpart);
Up=Y*Fpart;

%Displacement matrix
displacements=zeros(nonodes,1);
displacements(freenodes)=Up;
disp('Nodal displacements: ');

Nodal displacements:

disp(displacements);

1.0e-03 *

0.3333
0

% Strain and stress calculation


strain=zeros(noelement,1);
stress=zeros(noelement,1);
for i=1:noelement
strain(i,1)=(displacements(i+1,1)-displacements(i,1))/l;
stress(i,1)=E*strain(i,1);
end
disp('Stress and strain: ');

Stress and strain:

disp(stress);

-11

2
disp(strain);

-3.3333e-05

%Interpolation values of displacements,stress and strain within an


%element
syms x
displ_element=zeros(2,1);
U_element=zeros(2,1);
displ_element=displacements(1:2,1);
x=input('Enter the value for interpolation: ');
U_element=N*(displ_element);
strain=B*(displ_element);
stress=E*B*(displ_element);
Uvalue=subs(U_element);
strainvalue=subs(strain);
stressvalue=subs(stress);
disp('the value of displacement,strain and stress at given x is:');

the value of displacement,strain and stress at given x is:

fprintf('Displacements %6.12f\n',double(Uvalue));

Displacements 0.000200000000

fprintf('Strain %6.12f\n',double(strainvalue));

Strain -0.000033333333

fprintf('Stress %6.12f\n',double(stressvalue));

Stress -11.000000000000

% Analytical solution
%u-actual displacement at x
%P-strain
%S-Stress
u=a*(2*x*L-x^2)/(2*A*E);
P=a*(L-x)/(A*E);
S=a*(L-x)/A;
disp('the value of actual displacement,actual strain and actual stress at given x is:')

the value of actual displacement,actual strain and actual stress at given x is:

fprintf('Displacement %6.12f\n',double(u));

Displacement 0.000193939394

fprintf('Strain %6.12f\n',double(P));

Strain 0.000036363636

3
fprintf('Stress %6.12f\n',double(S));

Stress 12.000000000000

You might also like