Clear Filters
Clear Filters

I am getting error ".*" in vector multiplication

1 view (last 30 days)
Devesh Kumar
Devesh Kumar on 23 Apr 2023
Moved: Steve Miller on 23 Apr 2023
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;

Answers (1)

Dyuman Joshi
Dyuman Joshi on 23 Apr 2023
Moved: Steve Miller on 23 Apr 2023
Ke(1:6,1:6) is 6x6 and R is 3x3. You can not multiply a 6x6 matrix with a 3x3 matrix.

Categories

Find more on Operators and Elementary Operations 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!