1%Example of using MUMPS in matlab to compute diagonal of inverse of A 2 3% Change to true to test example complex arithmetic 4complex_arithmetic = false; 5 6% initialization of a matlab MUMPS structure 7id = initmumps; 8if (complex_arithmetic) 9 id = zmumps(id); 10else 11 id = dmumps(id); 12end 13load lhr01; 14mat = Problem.A; 15 16if (complex_arithmetic) 17 % To test complex version 18 mat = mat + i * speye(size(mat,1),size(mat,1)); 19end 20 21% JOB = 4 means analysis+factorization 22id.JOB = 4; 23if (complex_arithmetic) 24 id = zmumps(id,mat); 25else 26 id = dmumps(id,mat); 27end 28 29% Set the right hand side structure to requested entries of A-1 30id.RHS = speye(size(mat,1),size(mat,1)); % Sparse format required 31 32%call MUMPS solution phase to compute diagonal entries of A-1 33id.ICNTL(30)=1; % Ask for A-1 entries 34id.JOB=3; 35 36 37if (complex_arithmetic) 38 id = zmumps(id,mat); 39else 40 id = dmumps(id,mat); 41end 42 43% diagonal values have been computed in 44% the (sparse) matrix id.SOL, which has 45% the same structure as id.RHS 46 47% Compare diagonal of inverse computed by Mumps and by matlab 48disp(' '); 49disp('Computing 2-norm of error on diagonal of inverse:'); 50norm(diag( diag(diag(inv(mat)))-id.SOL ),2) 51 52% destroy mumps instance 53id.JOB = -2; 54if (complex_arithmetic) 55 id = zmumps(id) 56else 57 id = dmumps(id) 58end 59