Writing a loop to create a matrix

1 次查看(过去 30 天)
if N==1
Lambda = A;
elseif N==2
Lambda = [A A^2]';
elseif N==3
Lambda = [A A^2 A^3]';
elseif N==4
Lambda = [A A^2 A^3 A^4]';
elseif N==5
Lambda = [A A^2 A^3 A^4 A^5]';
end
Given that A is a matrix, how do I create a loop that creates:
Lambda = [A A^2 A^3... A^(N-2) A^(N-1) A^N]';

采纳的回答

Davide Masiello
Davide Masiello 2022-5-2
编辑:Davide Masiello 2022-5-2
Example
A = rand(3)
A = 3×3
0.5684 0.3903 0.6124 0.2054 0.1345 0.8194 0.4885 0.8078 0.9672
n = 10;
lambda = [];
for i = 1:n
lambda = [lambda;A.^i];
end
lambda
lambda = 30×3
0.5684 0.3903 0.6124 0.2054 0.1345 0.8194 0.4885 0.8078 0.9672 0.3231 0.1523 0.3750 0.0422 0.0181 0.6714 0.2386 0.6525 0.9355 0.1837 0.0594 0.2296 0.0087 0.0024 0.5502 0.1166 0.5271 0.9048 0.1044 0.0232 0.1406

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by