赞
踩
信息:The truss example to be solved using the completed code. The vertical and horizontal segments of the crane are made of aluminum (Young’s modulus E=70 GPa, and have a cross-section of 2 cm2. The diagonal truss elements are made of steel (Young’s modulus E=210 GPa, and have a cross-section of 3 cm2. The structure is subjected to a load P=6000 N applied as illustrated in the figure. The two support nodes are assumed fixed (i.e., x- and y-displacements are 0).
代码:
input代码
%读取input文件按顺序读取节点坐标,单元信息,受力节点信息,固定节点
fid = fopen('input.txt','rt'); %打开文件
NodeCoordinate = fscanf(fid,'%g',[3,25]); %读取节点坐标
NodeCoordinate = NodeCoordinate';
ElementMsg = fscanf(fid,'%g',[5,47]);%读取单元信息
ElementMsg = ElementMsg';
ForceNodeMsg = fscanf(fid,'%g',[3,1]);%读取受力节点信息(节点,方向,载荷)
FixNode = fscanf(fid,'%g',[2,1]);%读取固定节点信息
fclose(fid);
总体刚度矩阵的计算函数
function K = TotalStiffness_2DTRUSS(ElementMsg,NodeCoordinate) %输入单元信息,节点坐标,输出总体刚度矩阵 Num_Node = size(NodeCoordinate,1);%计算节点数 Num_Element = size(ElementMsg,1);%计算单元数 K = zeros(2*Num_Node,2*Num_Node);%预设总体刚度矩阵 for k = 1:Num_Element N1 = ElementMsg(k,2);%提取节点编号 N2 = ElementMsg(k,3); x1 = NodeCoordinate(N1,2);%提取节点坐标 x2 = NodeCoordinate(N2,2); y1 = NodeCoordinate(N1,3); y2 = NodeCoordinate(N2,3); L = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));%计算单元长度 C = (x2-x1)./L;%计算单元转角cos值 S = (y2-y1)./L;%计算单元转角sin值 A = ElementMsg(k,4);%提取单元截面积 E = ElementMsg(k,5);%提取单元弹性模量 Ke = E*A/L*[C*C C*S -C*C -C*S; %计算单元刚度矩阵 C*S S*S -C*S -S*S; -C*C -C*S C*C C*S; -C*S -S*S C*S S*S]; Locate = [2*N1-1,2*N1,2*N2-1,2*N2];%定位单元刚度矩阵坐标 %组装总体刚度矩阵K for i = 1:4 for j = 1:4 K(Locate(i),Locate(j)) = K(Locate(i),Locate(j)) + Ke(i,j); end end end end
求解函数
Num_Node = size(NodeCoordinate,1);%计算节点数
Num_Element = size(ElementMsg,1);%计算单元数
K = TotalStiffness_2DTRUSS(ElementMsg,NodeCoordinate);%计算K
F = zeros(2*Num_Node,1);%生成力初始边界条件
F(ForceNodeMsg(1)*2-2+ForceNodeMsg(2),1) = ForceNodeMsg(3);%生成力边界条件
%用置0置1处理边界条件
Num_FixNode=size(FixNode,1);
K0 = K;
for i = 1:Num_FixNode
%非主对角线元素全为0
K(FixNode(i)*2-1,:)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。