FEM-Course-Matlab/2.铁木辛柯梁的matlab有限元编程/cantilever.m

78 lines
1.8 KiB
Matlab

clear all;close all;clc;
%SI:m,kN,kPa
h=0.007;b=0.3;
E=3e7;A=b*h;I=b*h^3/12;v=0.2;
G=E*0.5/(1+v);
EI=E*I;
GA=G*A;
L=5;%杆件长度
Ele_L=0.01;%单元尺寸
ele_num=L/Ele_L;%单元个数
q=1;%1kN/m
W=q*L^4/(8*EI)%材料力学挠度计算公式
linetype={'-','--','-.'}
figure;
hold on;
for way=1:3
for i=1:ele_num
if way==1
ke(:,:,i)=BeamElementStiffness(EI,Ele_L);%欧拉梁单元
elseif way==2
ke(:,:,i)=TimoshenkoStiffness(EI,GA,Ele_L);%完全积分铁木辛柯梁单元(剪切自锁现象)
elseif way==3
ke(:,:,i)=TimoshenkoReduceStiffness(EI,GA,Ele_L);%减缩积分铁木辛柯梁单元
end
end
K=zeros((ele_num+1)*2);
for i=1:ele_num
K=BeamAssemble(K,ke(:,:,i),i,i+1); %全局刚度矩阵
end
k=[K(3:(ele_num+1)*2,3:(ele_num+1)*2)]; %***去除约束对应的刚度矩阵
f=zeros(2*(ele_num),1); %节点力f
for i=1:ele_num
f(2*(i-1)+1)=q*Ele_L;%****分布力大小为1*单元长度就是每个单元节点上的节点力,均布荷载转节点力
end
u=k\f;
U=zeros((ele_num+1)*2,1);%节点位移
U(3:(ele_num+1)*2)=u;%
for i=1:ele_num
Fe(i,:)=ke(:,:,i)*U((i-1)*2+1:(i-1)*2+4); %单元力=单元刚度矩阵*节点位移
end
% F=K*U; %全局刚度矩阵*节点位移=节点力
x = [0 : Ele_L:L]';
% figure;
% M=Fe(:,2);
% M(ele_num+1)=-Fe(end,4);
% hold on;
% title('Bending Moment Diagram');
% plot(x,M);
% y1 = zeros(1,ele_num+1);
% plot(x,y1,'k')
% xlabel('length')
% ylabel('Moment')
% title('moment diagram with constant thickness');
title('Displacment Diagram');
for i=1:length(x)
disp_plot_constant(i)=U(2*(i-1)+1);
end
aa=plot(x,disp_plot_constant,linetype{way},'linewidth',2);
aa.Color(4)=0.5
% figure;
% hold on;
% title('Rotation Diagram');
% for i=1:length(x)
% rot_plot_constant(i)=U(2*(i));
% end
% plot(x,rot_plot_constant);
% save data disp_plot_constant
end
legend('欧拉梁','铁木辛柯梁-完全积分','铁木辛柯梁-减缩积分');