1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 function d=%sp_diag(a,k)
11 // %sp_diag - implement diag function for sparse matrix, rational matrix ,..
14 if rhs==1 then k=0,end
19 l=find(ij(:,1)==(ij(:,2)-k))
28 if l==[] then d=sparse([],[],[mn,1]);return;end
29 d=sparse([ij(l,1)-i0,ones(ij(l,1))],v(l),[mn,1])
31 if m>1 then ij=ij(:,1);else ij=ij(:,2);end
34 d=sparse([],[],[nn,nn])
37 d=sparse([ij,ij+k],v,[nn,nn])
39 d=sparse([ij-k,ij],v,[nn,nn])