spdiags function algorithm in matlab

조회 수: 5 (최근 30일)
Behzad Hosseinzadeh
Behzad Hosseinzadeh 2015년 8월 16일
편집: Walter Roberson 2015년 8월 16일
Hi everybody, in MATLAB there is a spdiags function, creates sparse matrix by taking diagonal matrices, for example A = spdiags(B,d,m,n) creates an m-by-n sparse matrix by taking the columns of B and placing them along the diagonals specified by d. I want to know what algorithm is behind it, if I want to transfer my MATLAB code to c++, Is there any C++ codes has this function, or is any C++ library or class to do the same thing as this function do?

답변 (1개)

John D'Errico
John D'Errico 2015년 8월 16일
편집: John D'Errico 2015년 8월 16일
What is the algorithm? You know the various diagonal elements, and thus the set of indexes for those diagonals and various super/sub diagonals. Stuff the values into those entries.
In MATLAB, this would involve a final call to sparse. If you are writing the code in C, you know (in theory, if you understand sparse matrices) what order to stuff the entries into the array to be efficient.
If you want to know the EXACT algorithm specifics of what spdiags does, then just do this:
type spdiags
and read the code.
  댓글 수: 1
Cedric
Cedric 2015년 8월 16일
편집: Walter Roberson 2015년 8월 16일
And for the way MATLAB handles/implements sparse matrices, the tech note is here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by