24_devang_question4_part1
24_devang_question4_part1
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: ');
disp(Kglobal);
33000 -33000
-33000 33000
1
disp('Global force matrix: ');
fprintf('%6.4f\n',double(f));
11.0000
10.0000
%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
disp(stress);
-11
2
disp(strain);
-3.3333e-05
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