Making matrix whose submatrices are from for loop

조회 수: 2 (최근 30일)
Ljix
Ljix 2016년 2월 19일
답변: Walter Roberson 2016년 2월 19일
I'm trying to construct matrix whose submatrices are obtained in for loop. for loop is
for j = 2:Jmax
P(j-1)=(sqrt(-2*p(j-1)+1)/sqrt(-2*p(j-1)))*(I-(p(j)+p(j-1))*inv(A+p(j)*I))
V(j)=P(j-1)*V(j-1);
W=[W V(j)]
Is this ok? Also where to put V(1), can it be outside for loop?
  댓글 수: 2
James Tursa
James Tursa 2016년 2월 19일
What are the dimensions of the variables? In particular, is P(j-1) expected to be a scalar or a matrix?
Ljix
Ljix 2016년 2월 19일
P(j-1) is a matrix, and V(j) is a vector.

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 19일
for j = 2:Jmax
P{j-1}=(sqrt(-2*p(j-1)+1)/sqrt(-2*p(j-1)))*(I-(p(j)+p(j-1))*inv(A+p(j)*I))
V{j}=P{j-1}*V{j-1};
W=[W V{j}]
It is not clear whether p (lower-case) is intended to be a matrix or a vector. If it is intended to be a matrix then
for j = 2:Jmax
P{j-1}=(sqrt(-2*p{j-1}+1)/sqrt(-2*p{j-1}))*(I-(p{j}+p{j-1})*inv(A+p{j}*I))
V{j}=P{j-1}*V{j-1};
W=[W V{j}]
Based upon the p(j)*I, my suspicion would be that p(j) is intended to be a scalar, but that is not certain.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by