# How to get values out of a matrix equation, when one of its elements is an array?

2 views (last 30 days)
Zeyad Elsayed on 1 Jun 2019
Commented: Zeyad Elsayed on 5 Jun 2019
Hello everyone,
My question is how can I solve a matrix equation, when one of its elements is an array?
This error comes up in the command window preventing 'q' to be found. "Dimensions of arrays being concatenated are not consistent."
% Stating variables
omega = 100
M_22 = (0:0.1:20);
C_22 = (0:0.2:40);
F_1 = (0:0.4:80);
% Creating Matrix
M = [1 0; 0 M_22];
C = [1 2; -2 C_22];
K = [100 0; 0 100];
F = [F_1; F_2];
% Equations
Z = -(omega^2)*M + omega*j*C + K;
Z_inverse = inv(Z);
q = Z_inverse*F;

Show 1 older comment
Zeyad Elsayed on 4 Jun 2019
So instead of having arrays in matrix, I created a for loop that calculates M_22, C_22 and F_1 individually each time step lets say (t = 0:0.1:20). However, I cant view all the value of q when t is changing, only the last t shows in the workspace. I tried using the following to have it in a vector:
v3 = [v3; q] % Inserting values of q in a vector form
But as q is a matrix (2 rows(q_1 and q_2) x 1 column(representing each time step)) , when I use the code above, both values are entered together in one long column.
Does anyone know how I can separate the two values? Maybe have 2 matrices, one I can name q_1 and one q_2, each showing how they change with time t.
NB: There are equations to calculate M_22, C_22 and F_1, if you were wondering how I created the for loop.
Walter Roberson on 4 Jun 2019
tvals = 0:0.1:20;
numt = length(tvals);
v3 = zeros(2, numt);
for tidx = 1 : numt
t = tvals(tidx);
....
v3(:, tidx) = q;
end
Zeyad Elsayed on 5 Jun 2019
Perfect it worked! Thanks Walter, I want to Accept your answer but for some reason I cant find how to do this. Probably because its submitted as a comment.