当前位置:   article > 正文

Matlab 二维杆单元有限元模型编程求解代码_空间杆单元的模态分析代码

空间杆单元的模态分析代码

Matlab 二维杆单元有限元模型编程求解代码

在这里插入图片描述
信息: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); 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

总体刚度矩阵的计算函数

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

求解函数

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,:)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/837487
推荐阅读
相关标签
  

闽ICP备14008679号