1function ex41(np,opt) 2% 3% ex41(np,opt) - receives a matrix and vector from MATLAB via socket 4% solves the linear system and returns the solution vector 5% 6% Run with option -on_error_attach_debugger to debug 7% 8% Requires the MATLAB mex routines in ${PETSC_DIR}/share/petsc/matlab and ${PETSC_DIR}/${PETSC_ARCH}/lib/matlab, 9% these require PETSc be configured with --with-matlab 10% Make sure that ${PETSC_DIR}/share/petsc/matlab and ${PETSC_DIR}/${PETSC_ARCH}/lib/matlab is in your MATLABPATH or 11% $prefix/share/petsc/matlab and $prefix/lib/matlab if you ran ./configure with --prefix 12% 13if (nargin < 1) 14 np = 1; 15end 16if (nargin < 2) 17 opt = ' '; 18end 19launch('./ex41 ',np,opt); 20 21p = PetscOpenSocket; 22b = [1 2 3]; 23A = sparse([3 2 1; 1 3 2; 1 2 3]); 24PetscBinaryWrite(p,b); 25PetscBinaryWrite(p,A); 26x = PetscBinaryRead(p); 27b' - A*x' 28x' - A\b' 29close(p); 30