The function spdiags extracts and creates sparse band and diagonal matrices and is a generalization of the MATLAB function diag. We will only use one of its various forms. To create a pentadiagonal matrix, create vectors that specify the diagonals. We will call these diagonals12345 where12are the subdiagonals and45are the superdiagonals. For an matrix, each vector must have length To create the matrix, execute
The parameter -2:2 specifies that the diagonals are located at offsets and from the main diagonal.
Create a pentadiagonal matrix with sub- and superdiagonalsTand diagonalT Show the matrix is positive definite, with an approximate condition number of
Using0 and a random apply cg using tol−14and maxiterIn each case, output the residual.
Use precg with the same tolerance and niter Output the residual.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here