フィルターのクリア

Error with spdiags size dimensions in pentadiagonal matrixes

9 ビュー (過去 30 日間)
Pol
Pol 2024 年 5 月 9 日
コメント済み: Pol 2024 年 5 月 13 日
I'm trying to create a sparse pentadiagonal matrix for a derivation discretization problem I'm working on. This matrix sould have the diagonals [1, -8, 0, 8, -1], with the value 0 being the one centered on the main diagonal.
I'm getting the error
Error using spdiags
For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d).
Error in burnfile (line 15)
D1 = spdiags([1 -8 0 8 -1],-2:2,nx,nx);
It boggles me because if I try to paste in the tridiagonal example in the spdiagonal documentation page, it gives me the same error instead of working (having cleared all variables and on a clean notebook).
I'm working with Matlab R2022b, in case that's relevant.
The code I'm using is as follows:
nx = 1000;
D1 = spdiags([1 -8 0 8 1],-2:2,nx,nx);
full(D1)
ans = 1000x1000
0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  4 件のコメント
Matt J
Matt J 2024 年 5 月 9 日
編集済み: Matt J 2024 年 5 月 9 日
Sorry, but why can't it be tested in a previous version? Also I don't know what you mean by "see above"
Your code has been run in your post using the forum's Matlab engine. That's what has produced the output there. However, only R2024a is available for this:
Torsten
Torsten 2024 年 5 月 9 日
編集済み: Torsten 2024 年 5 月 9 日
@Matt J answered your first question. With "see above", I mean "look at your question: your code can be executed and does not throw an error in R2024a".

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

採用された回答

Matt J
Matt J 2024 年 5 月 9 日
編集済み: Matt J 2024 年 5 月 9 日
Does anyone know if spdiags has undergone any significant updates between versions these 2 years?
Yes, support for the syntax you are using is relatively new. The old way is,
nx = 1000;
e=ones(nx,1);
D1 = spdiags(e*[1 -8 0 8 1],-2:2,nx,nx);
full(D1)
ans = 1000x1000
0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -8 0 8 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  6 件のコメント
Steven Lord
Steven Lord 2024 年 5 月 10 日
FYI there's an entry in the Release Notes for this functionality in spdiags. It was introduced in release R2024a.
To see older documentation, click on the Support link at the top of many MathWorks webpages (including this one.) On the right side of the page, under the release number of the current release (indicating the Help Center is showing the documentation for the current release) click on Other Releases. You can select from one of last 5 years worth of releases (10 releases.) For example this is the documentation page for spdiags in release R2022b and this is the documentation page for spdiags in the current release. They look at a quick skim to be very similar until you get to the section for the Bin input argument and the Version History section.
Pol
Pol 2024 年 5 月 13 日
Ahh! That makes a lot of sense, thanks for the detailed explanation, Steven. I did try to find the previous documentation as Torsten pointed out I should have done, of course, but I just sticked to Google and it just wouldn't show up. Thanks! I will always check on the appropiate documentation from now on!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by