简体   繁体   中英

How can I solve a linear system in Matlab of the type AX = B, where each element of the matrix B is a submatrix?

I would like to solve a linear system AX = B where A is nxn matrix with constant elements, the matrix B is of type nx1. However, each element of the matrix B is a nx1 vector of type (this occurs because each element bij is time-varying).

%%% 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.

I tried to solve the segunte form:

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

But I do not know if it's the best way.

You can just do the following.

C = reshape(rand(6,1,251), 6, 251); % Or just create rand(6, 251);
A = rand(6,6);
X = A \ C;

This will give you the same results and will be faster than the for loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM