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일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2022년 5월 2일

편집:

2022년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by