计算越来越多的矩阵的乘积

问题描述 投票:0回答:1

我有一个常数C [0],其值已知。我们定义一个名为m的矩阵,其元素如下:

M

最初,生成 | M_11 M_12 | M_i ≜ | | | M_21 M_22 | 2x2矩阵(即m)。然后,对于M1,...,M51之间的每个整数,我需要计算一个矩阵,使得

m

如何提取乘积矩阵的for m=1, P1 = M1 for m=2, P2 = M1.M2 for m=3, P3 = M1.M2.M3 and so on 并将其与P_11相对应?

matlab matrix iteration product matrix-multiplication
1个回答
0
投票

由于尚不清楚您要问的是什么,因此我在同一答案中提供了两种解决方案。有关更多信息,请参见下面的代码中的注释。

m

将导致:

function q59596709 %% Definitions: rng(59596709); % for reproducibility m = 5; SZ = 2; %% Preallocation [P_arr,P_mat] = deal(zeros(m,1)); % preallocation %% Generate data: M = rand(SZ,SZ,m); %% Perform ARRAY multiplication for ind1 = 1:m tmp = prod(M(:,:,1:ind1),3); P_arr(ind1) = tmp(1); % get the first (i.e. 1,1) element end %% Perform MATRIX multiplication tmp = eye(SZ); for ind1 = 1:m tmp = tmp * M(:,:,ind1); P_mat(ind1) = tmp(1); % get the first (i.e. 1,1) element end %% Show the first element: figure(); plot(1:m, P_arr, 1:m, P_mat); xlabel('m'); ylabel('value'); set(gca, 'FontSize', 14); legend('M_{11}, ARRAY multiplication', 'M_{11}, MATRIX multiplication');

© www.soinside.com 2019 - 2024. All rights reserved.