- https://www.mathworks.com/help/matlab/ref/for.html
- https://www.mathworks.com/help/matlab/cell-arrays.html
- https://www.mathworks.com/help/matlab/ref/transpose.html
Kg1 = transpose(T1)*K1*T1 Kg2 = transpose(T2)*K2*T2 Kg3 = transpose(T3)*K3*T3 를 for문으로 깔끔하게 만들수 없을까요??
1 view (last 30 days)
Show older comments
Kg1 = transpose(T1)*K1*T1
Kg2 = transpose(T2)*K2*T2
Kg3 = transpose(T3)*K3*T3
를 for문으로 깔끔하게 만들수 없을까요??
0 Comments
Answers (1)
Abhimenyu
on 5 Apr 2024
Hello,
From the information shared, I inferred that you would like to clean your code using MATLAB's "for" loop. Assuming there is a collection of transformation matrices T and stiffness matrices K, to calculate the global stiffness matrices Kg for each pair using the "for" loop, please refer to the below-mentioned MATLAB example code for better understanding:
% Define the transformation matrices and stiffness matrices
T1 = ...; % Define your matrix
T2 = ...; % Define your matrix
T3 = ...; % Define your matrix
K1 = ...; % Define your matrix
K2 = ...; % Define your matrix
K3 = ...; % Define your matrix
% Store the matrices in cell arrays for easy iteration and to handle
% different sized matrices
T_matrices = {T1, T2, T3};
K_matrices = {K1, K2, K3};
Kg_matrices = cell(1, length(T_matrices)); % Preallocate cell array for global stiffness matrices
% Loop through each pair of T and K matrices
for i = 1:length(T_matrices)
T = T_matrices{i};
K = K_matrices{i};
Kg = transpose(T) * K * T; % Calculate the global stiffness matrix
Kg_matrices{i} = Kg; % Store the result
end
% Kg_matrices now contains Kg1, Kg2, Kg3 respectively
Please refer to the below-mentioned MATLAB R2024A documentation links to know more about "for" loop, "cell" array and "transpose" function respectively:
I hope this helps!
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!