Writing a loop to create a matrix
1 view (last 30 days)
Show older comments
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]';
0 Comments
Accepted Answer
Davide Masiello
on 2 May 2022
Edited: Davide Masiello
on 2 May 2022
Example
A = rand(3)
n = 10;
lambda = [];
for i = 1:n
lambda = [lambda;A.^i];
end
lambda
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!