How can I write the following matrix
I define n=100
And I generate the following code
D= toeplitz ([0 1 zeros(1, n-2) -1]/ (2*h))
but I get wrong matrix. How can I correct it?

6 件のコメント

Sindar
Sindar 2020 年 5 月 7 日
try diag (good for small problems) or spdiag (better examples)
Zeynep Toprak
Zeynep Toprak 2020 年 5 月 7 日
please can you write in a clear way. I am new learner of matlab, and I try to learn it by myself. So, I do not know how to use what you said. Thanks a lot.
Sindar
Sindar 2020 年 5 月 7 日
click the links and read the examples
Sindar
Sindar 2020 年 5 月 7 日
I'd been using Matlab for years and still found it useful
Zeynep Toprak
Zeynep Toprak 2020 年 5 月 7 日
okay, thanks for helping, but it is very difficult. Thanks a lot again.
Gokberk Yildirim
Gokberk Yildirim 2020 年 5 月 16 日
Actually, it can be done with this Zeynep.
c = [0 -1 zeros(1,n-3)];
r = [0 1 zeros(1,n-3)];
D = toeplitz(c,r) / (2*h)

サインインしてコメントする。

 採用された回答

John D'Errico
John D'Errico 2020 年 5 月 7 日
編集済み: John D'Errico 2020 年 5 月 7 日

0 投票

Try this:
n = 100;
D = (diag(ones(n-1,1),1) - diag(ones(n-1,1),-1))/(2*h);
You can also use spdiags. or sparse, or many other tools. But diag as I did it above is about the simplest way.

1 件のコメント

Zeynep Toprak
Zeynep Toprak 2020 年 5 月 7 日
Many thanks for your great help!! :) I use this matrix in this question my question is here. But I get an error message. Please can you take a look at it? (This is not assignment or something else like this. On these lockdown days, I try to learn matlab by myself, and I have no one to ask or to learn) Many thanks again.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by