我想解一个线性系统AX = B,其中a是一个常元素矩阵nxn,矩阵B是nx1型。然而,矩阵B的每个元素都是类型为nx1的向量(这是因为每个元素bij都是时变的)。
%%% Example
t = 0:0.002:0.5; %% Time
A = [1 0 -1 0 0 0; ...
0 -1 0 0 1 0; ...
r12y, r32y-r12x r32x 0 0; ...
0 0 -1 0 1 0; ...
0 -1 0 0 1 0; ...
0 r23y-7-r43y r23x r43x];
%% Where rij is constant
% Construction 6x1 matrix C
C = [m2.*A2x ; ...
m2.*FG2-a2y; ...
ICM2.*Alpha2; ...
m3.*A3X ; ...
m3.*a3y-FG3; ...
Icm3.*Alph8a3];
%% Where A2x, a2y, A3X, a3y, alpha2, Alpha3 are elements of the matrix C that are time-varying.
我试着解决segunte形式:
C = rand (6,1,251);
A = rand (6,6);%
X = zeros (6, size (C, 3));
for i = 1: size (C, 3)
X (:, i) = A C (:,:, i);
end
但我不知道这是不是最好的方法。
您可以这样做:
C = reshape(rand(6,1,251), 6, 251); % Or just create rand(6, 251);
A = rand(6,6);
X = A C;
这将给你相同的结果,并且将比for循环更快。