Error with spdiags size dimensions in pentadiagonal matrixes
11 次查看(过去 30 天)
显示 更早的评论
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)
4 个评论
采纳的回答
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)
6 个评论
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!