``` clear; clc; close all; format default; profile on; ``` visualize the nonzero elements of a matrix ``` spy() ``` matlab is column-major that explains so much accessing column wise is much faster than row wise in Matlab sparsity is the fraction of the matrix that are zeros only use sparse matrices for matrices that are actually sparse enough for it to matter Operations that preserve sparsity: - addition - subtraction - element-wise multiplication - kronecker multiplication Operations that do NOT preserve sparsity - algebraic multiplication - inverse or pseudo-inverse - eigen-decomposition, SVD ``` surf(X,Y,Z) mesh(X, Y, Z); contour contourf colorbar view(2); shading interp; print('-dpng', '-r400', 'contour_plots'); savefig('contour_plots') ``` plot errors in log log scale show how much time different functions are taking ``` profile on % code here profile viewer ```