我想求解线性系统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.
我试图解决这种形式:
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
但我不知道这是不是最好的方式。
答案 0 :(得分:3)
您可以执行以下操作。
C = reshape(rand(6,1,251), 6, 251); % Or just create rand(6, 251);
A = rand(6,6);
X = A \ C;
这将为您提供相同的结果,并且比for循环更快。