how to create this matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
can anyone help me to construct this matrix
blj=(-2)^j-l if l<j
blj=1 if l=j
blj=0 if l>j
댓글 수: 0
채택된 답변
Brian Hart
2018년 12월 22일
편집: Brian Hart
2018년 12월 22일
Hi diadalina,
I think it would look something like this...
iLength = 5; %rows
jLength = 7; %cols
b=zeros(iLength, jLength);
for i = 1:iLength
for j = 1:jLength
if i == j; b(i,j) = 1; end
if i < j; b(i,j) = (-2)^(j-i); end
end
end
disp(b)
gives a result of:
1 -2 4 -8 16 -32 64
0 1 -2 4 -8 16 -32
0 0 1 -2 4 -8 16
0 0 0 1 -2 4 -8
0 0 0 0 1 -2 4
댓글 수: 2
Guillaume
2018년 12월 22일
It is unclear if the formula in the question is
as written or
which would make more sense. One thing for sure, it's not likely to be
which is what you calculate.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199633/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199634/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199635/image.png)
추가 답변 (2개)
Guillaume
2018년 12월 22일
편집: Guillaume
2018년 12월 22일
Assume your formula is
and not what you have written:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199636/image.png)
nrows = 5; %number of rows. You haven't specified
ncols = 7; %number of columns. You haven't specified
b = toeplitz([1, zeros(1, nrows-1)], (-2).^(0:ncols-1))
If the formula is what you have actually written,
, then
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199637/image.png)
b = triu((-2).^(1:ncols) - (1:nrows)', 1) + eye(nrows, ncols)
Stephan
2018년 12월 22일
편집: Stephan
2018년 12월 22일
Hi,
do you want a square matrix? Is the calculation correct without any brackets? My calculation follows the way you wrote the formula - if wrong set the brackets corresponding to your expected result.
Then try:
k=3;
[m,n]=meshgrid(1:k);
A=triu((-2).^n-m,1) + eye(k)
Best regards
Stephan
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!