how to create this matrix?
古いコメントを表示
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
採用された回答
その他の回答 (2 件)
Assume your formula is
and not what you have written:
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
b = triu((-2).^(1:ncols) - (1:nrows)', 1) + eye(nrows, ncols)
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
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
