Page 68 - Numerical Methods for Chemical Engineering
P. 68
Problems 57
end
if(k < N)
A(k,k+1) = - 1;
end
end
b = ones(N,1);
x=A\b;
Such sparse systems may be generated more efficiently through use of specialty functions
such as spdiags. A list of sparse matrix function is generated by the command sparfun.
Gaussian elimination is used to form the decomposition PA = LU, where L is lower
triangular, U is upper triangular, and P is a permutation matrix, by
[L, U, P] = lu(A);
T
When A is positive-definite, the decomposition A = R R, with R upper triangular, is
performed by Cholesky factorization,
R = chol(A);
The determinant of a matrix is computed, through LU factorization, by
det A = det(A);
A list of functions available for matrix manipulation is returned by
matfun
Problems
1.A.1. Solve the following linear system by hand, using Gaussian elimination with partial
pivoting, followed by backward substitution.
−2x 1 + 3x 2 + x 3 =−6
−x 1 + 3x 2 + 3x 3 =−8 (1.262)
2x 1 − x 2 + x 3 = 2
1.A.2.Forthematrixofthesysteminproblem1.A.1,computebyhandtheLUdecomposition
(you do not need to use pivoting).
1.A.3. Consider the problem of fitting a polynomial to the values of f(x) at points x 0 < x 1 <
x 2 < ··· < x N . We wish to find the coefficients of a polynomial
2
p(x) = a 0 + a 1 x + a 2 x + ··· + a N x N (1.263)
such that p(x k ) = f (x k ) for all k = 0, 1,..., N. Using the “\” linear solver, write a routine
that accomplishes this task, of the form
a = calc poly coeff(x,f);
x, f, and a are vectors of x k , f (x k ), and a k respectively.