Error with spdiags size dimensions in pentadiagonal matrixes
Show older comments
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 Comments
Torsten
on 9 May 2024
Works in R2024a, and we can't test it in your release (see above).
Pol
on 9 May 2024
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:

Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!