我试图将两个单独的值中的8个矩阵保存在两个单独的值中,用于'循环使我可以倍增T& kloc找到一个值' k'。它们是两个独立的环路。两者都给出了8个矩阵,但是当我尝试将它们相乘时,它们的值将作为迭代中的最后一个值。此外,当我试图将其中一个插入另一个&有一个大的'为'循环我最终得到了超过8个输出矩阵,用于T或kloc(无论哪个嵌套)。我很感激任何帮助。感谢。
%-------------------------Givens/Constants--------------------------%
E = 10200; %ksi
b = 1; %in
h = 0.25; %in
I = (b*h^3)/12; %in^4
A = b*h;
%%Lengths &Angles
addangle = atand(8/16.25);
theta1 = 0;
theta2 = atand(16.25/8);
theta3 = 2*addangle + 63.7886;
theta4 = 90;
L1=8;
L3 = 16.25/sind(63.7886);
L2 = 16;
L4 = 16.25;
%--------------------------------------------------------------------%
%%Local stiffness matrices
%The angle between 8 beams of structure from the positive x-axis
%(In order of member ID 1:8)
for theta=[theta1,theta1,theta1,theta1,theta3,theta2,theta3,theta4]
ct = cosd(theta);
st = sind(theta);
T =[ct,st,0,0,0,0; -st,ct,0,0,0,0;...
0,0,1,0,0,0;0,0,0,ct,st,0; 0,0,0,-st,ct,0;0,0,0,0,0,1];
end
%Length of 8 seperate beams in truss structure
%(In order of member ID 1:8)
for L=[L3,L1,L1,L3,L2,L2,L2,L4]
C = (E*I)/(L^3);
line1 = [(A*L^2)/I,0,0,-(A*L^2)/I,0,0];
line2 = [0,12,6*L,0,-12,6*L];
line3 = [0,6*L,4*L^2,0,-6*L,2*L^2];
line4 = [-(A*L^2)/I,0,0,(A*L^2)/I,0,0];
line5 = [0,-12,-6*L,0,12,-6*L];
line6 = [0,6*L,2*L^2,0,-6*L,4*L^2];
kloc = C*[line1;line2;line3;line4;line5;line6];
end
%Need to calculate 8 matrices of 'k' where...
% k = TT*kloc*T
答案 0 :(得分:0)
合并循环
两个循环长度相同,因此您可以使用单个循环
theta=[theta1,theta1,theta1,theta1,theta3,theta2,theta3,theta4];
L=[L3,L1,L1,L3,L2,L2,L2,L4];
k = zeros(1,length(L));
for id=1:length(theta) % or length(L)
theta_loop = theta(id);
L_loop = L(id);
% calculate T
% calculate C and kloc
k(id) = TT*kloc*T;
end
更高维度
您可以将所有T
,C
和kloc
保存到更高的维度,但是您必须小心维度,您可能还需要预先初始化多维阵列(张量)提前。像这样的东西, 注意伪代码
for id=1:length(theta)
theta_loop = theta(id);
% calculate T
T(:,:,id) = T;
end
for id=1:length(L)
L_loop = L(id);
% calculate C and kloc
kloc(:,:,id) = kloc;
end
k = kloc*T;
您还可以尝试将数据存储在单元格中,其中每个单元格包含单独的T
,kloc
等。但我不是细胞的忠实粉丝所以我不会进入详情。