I am getting error ".*" in vector multiplication
23 ビュー (過去 30 日間)
古いコメントを表示
This is the code
clear; clc;
% Define element properties
E = 2e11; % Young's modulus
A = pi/4 * 1^2; % Cross-sectional area
L = 20; % Element length
I = pi/64 * 1^4; % Moment of inertia
% Define rotation matrix
theta = pi/2; % Rotation angle
R = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
% Define elemental stiffness matrix
Ke = [E*A/L 0 0 -E*A/L 0 0;
0 12*E*I/L^3 6*E*I/L^2 0 -12*E*I/L^3 6*E*I/L^2;
0 6*E*I/L^2 4*E*I/L 0 -6*E*I/L^2 2*E*I/L;
-E*A/L 0 0 E*A/L 0 0;
0 -12*E*I/L^3 -6*E*I/L^2 0 12*E*I/L^3 -6*E*I/L^2;
0 6*E*I/L^2 2*E*I/L 0 -6*E*I/L^2 4*E*I/L];
% Assemble global stiffness matrix
K_global = zeros(18, 18);
% Element 1
K_global(1:6, 1:6) = K_global(1:6, 1:6) + R.' * Ke(1:6, 1:6) * R;
% Element 2
K_global([4 5 6 7 8 9], [4 5 6 7 8 9]) = K_global([4 5 6 7 8 9], [4 5 6 7 8 9]) + R.' * Ke([4 5 6 1 2 3], [4 5 6 1 2 3]) * R;
% Element 3
K_global([7 8 9 10 11 12], [7 8 9 10 11 12]) = K_global([7 8 9 10 11 12], [7 8 9 10 11 12]) + R.' * Ke([4 5 6 1 2 3], [4 5 6 1 2 3]) * R;
% Element 4
K_global([10 11 12 13 14 15], [10 11 12 13 14 15]) = K_global([10 11 12 13 14 15], [10 11 12 13 14 15]) + R.' * Ke([4 5 6 1 2 3], [4 5 6 1 2 3]) * R;
% Element 5
K_global([13 14 15 16 17 18], [13 14 15 16 17 18]) = K_global([13 14 15 16 17 18], [13 14 15 16 17 18]) + R.' * Ke([4 5 6 1 2 3], [4 5 6 1 2 3]) * R;
% Display global stiffness matrix
disp(K_global);
Error warning coming is
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the
number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for
elementwise multiplication.
Error in assignment2_Releaiblity (line 26)
K_global(1:6, 1:6) = K_global(1:6, 1:6) + R.' * Ke(1:6, 1:6) * R;
0 件のコメント
回答 (1 件)
Dyuman Joshi
2023 年 4 月 23 日
移動済み: Steve Miller
2023 年 4 月 23 日
Ke(1:6,1:6) is 6x6 and R is 3x3. You can not multiply a 6x6 matrix with a 3x3 matrix.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!