create sparse matrix from diagonal arrays
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack Silver
el 10 de Abr. de 2014
Comentada: Jack Silver
el 24 de Abr. de 2014
I have the 7 diagonal that come from a 3D finite volume discretization in separate arrays. These 7 arrays have 3D shape and correspond to each elements of the stencil for all points: top, bottom, east, west, north south and central point. I would like to create a sparse matrix object from these arrays, but I feel a little lost with the spdiag documentation. Help would be gratly apreaciated.
0 comentarios
Respuesta aceptada
Bill Greene
el 14 de Abr. de 2014
This doesn't exactly answer your question but still may be useful. This example:
shows how to create sparse finite difference matrices for the 1D, 2D, and 3D Poisson equation. For the 3D case, the 7-point stencil is used. For the 1D case, the use of spdiags is straightforward:
K1D = spdiags(ones(n,1)*[-1 2 -1],-1:1,n,n); % 1d Poisson matrix
Possibly you've already seen this simple example. But you'll notice that the kron function is used to create the 2D and 3D matrices. Use of spciags to create these is not nearly as straightforward as in the 1D case.
You might also find this blog useful:
As it explains, the key to efficiently creating sparse matrices in MATLAB is to pre-compute an array of row, column, value triplets and then use a single call to the sparse function to convert these to a sparse matrix.
Bill
Más respuestas (2)
Andrew Newell
el 10 de Abr. de 2014
MATLAB supports sparse matrices, but for 3D arrays you'll need to visit the File Exchange and get N-dimensional sparse arrays by Matt J.
2 comentarios
Andrew Newell
el 11 de Abr. de 2014
I'm still having trouble understanding what you mean. Could you attach a file with some data?
Ver también
Categorías
Más información sobre Sparse Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!