Lab2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ed, thus saving memory space and many subsequent computations. The Matlab command that generates an n × n sparse matrix from some given diagonal entries is A = spdiags(D,[-1 0 1],n,n); The argument “[-1 0 1]” indicates that the first, second, and third columns of “D” are the first lower, main, and first upper diagonals of “A”. 9. Initialize the RHS of the linear system by using B = zeros(n,1); 10. (Ex.) Add a line that computes the RHS “B”, i.e. “B” should store the values 0, 3 3 (f3 − f2 ) − (f2 − f1 ), h2 h1 3 ..., hn−1 (fn − fn−1 ) − 3 hn−2 (fn−1 − fn−2 ), 11. Solve the linear system by Gaussian elimination using the command y = A\B; After this line, the column vector “y” should contain the coefficients c1 , c2 , . . . , cn . 3 0 12. Extract the coefficients a1 , . . . , an−1 from “f” and the coefficients c1 , . . . , cn−1 from “y...
View Full Document

This document was uploaded on 10/10/2013.

Ask a homework question - tutors are online