A fellow student needed to train the Laplace expansion. This Matlab-script generates a configurable count of sparse matrices with configurable dimension.
Checking the results is made easy by the automatically generated determinants.
Use
help trainLaplaceExpand
to get more help. Or use
[M D]=trainLaplaceExpand(40,4);
to generate 40 sparse matrices with dimension 4 and store them in M. The determinants are stored in the workspace variable D. (
download this example)
% train LaplaceExpansion (calculating determinant of sparse matrices) % % [M D] = trainLaplaceExpand(numMatrices, dim) generates a 3-dimensional % matrix M and vector D with the corresponding determinants % numMatrices count of sparse matrices to generate % dim dimension of sparse matrices % % (c)2010 by Torsten Reuschel, E-Mail: matlabhelp@fuesika.de % % This program is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program. If not, see <http://www.gnu.org/licenses/>. function [M D] = trainLaplaceExpand(numMatrices, dim) fprintf('Generating %1.f matrices...\n', numMatrices); %initialize memory M = zeros(dim,dim,numMatrices); D = zeros(numMatrices,1); %generate matrices and calculate determinants for i = 1:numMatrices, M(:,:,i) = makeSparse(dim); D(i) = det(M(:,:,i)); end function ma = makeSparse(dim) ma = round(sprand(dim,dim,2)*5); end end