storing values in for loop

i want to make a vector consists of following fi elements from for loop how can i do that ??
where F=[CA;CA^2;CA^3;...etc]
how can i store values of fi in above matrix ???
Code:
Am=[0 1 0;0 0 1;0 -1.8 2.7];
Bm=[0;0;1];
Cm=[6 5 1];
Dm=0;
N2=10;
Nu=2;
[n,n1]=size(Am);
Om=zeros(n,1);
A=[Am Om;Cm*Am 1];
B=[Bm;Cm*Bm];
C=[0 0 0 1];
% To get G,F
for i=1:N2
fi=C*A^i;
end

 채택된 답변

Wayne King
Wayne King 2012년 4월 25일

1 개 추천

Looks like you C is a 1x4 row vector and A 4x4.
If you want to store the results as rows of a matrix
B = A;
N2 = 10;
for nn = 1:N2
out(nn,:) = C*B;
B = B*A;
end
You also always initialize out with zeros first
out = zeros(N2,4);
before you enter the loop.
Actually if your C is really just [0 0 0 1], then all you're obtaining is the last row of the powers of the matrix A.
for nn = 1:N2
B = A^nn;
out(nn,:) = B(end,:);
end

댓글 수: 1

Marwa  Ali
Marwa Ali 2012년 4월 25일
ty it really helped;
but if i had matrix in form of G=[CB 0 0...;CAB CB 0 0 ...;C(A^2)B CAB 0 0...);C(A^N2-1)B....CA^(N2-Nu)B];
is there anyway to store it directly or i have to use answer and form this matrix myself ??

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2012년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by