Clear Filters
Clear Filters

Kg1 = transpose(T1)*K1*T1 Kg2 = transpose(T2)*K2*T2 Kg3 = transpose(T3)*K3*T3 를 for문으로 깔끔하게 만들수 없을까요??

3 views (last 30 days)
Kg1 = transpose(T1)*K1*T1
Kg2 = transpose(T2)*K2*T2
Kg3 = transpose(T3)*K3*T3
를 for문으로 깔끔하게 만들수 없을까요??

Answers (1)

Abhimenyu
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!

Categories

Find more on 루프와 조건문 in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!