Читать книгу Solutions Manual to Accompany An Introduction to Numerical Methods and Analysis - James F. Epperson - Страница 16
2.6 SOLUTION OF TRIDIAGONAL LINEAR SYSTEMS Exercises:
Оглавление1 Use the tridiagonal algorithm in this section to compute the solution to the following system of equations:Solution: After the elimination step is completed, the triangular system isand the solution is
2 Write a computer code to solve the previous problemSolution: The following is a MATLAB script that produced the previous solutionfunction [delta, f, x] = trisol(l,d,u,b) n = length(d); x = zeros(n,1); for k=2:n d(k) = d(k) - u(k-1)*l(k)/d(k-1); b(k) = b(k) - b(k-1)*l(k)/d(k-1); end x(n) = b(n)/d(n); for k=(n-1):(-1):1 x(k) = (b(k) - u(k)*x(k+1))/d(k); end delta = d; f = b;
3 Use the algorithm of this section to solve the following system of equations:You should get the solution .
4 Write a computer code to solve the previous problem.
5 The diagonal dominance condition is an example of a sufficient but not necessary condition. That is, the algorithm will often work for systems that are not diagonally dominant. Show that the following system is not diagonally dominant, but then use the tridiagonal algorithm in this section to compute the solution to it:You should get the solution .Solution: The matrix fails to be diagonally dominant because of the values in the second, third, and fourth rows. However, if we apply the algorithm, we get the triangular systemand then the correct values for the solution, . (It always helps to type in the correct right‐side vector when checking these things.)
6 Use the tridiagonal algorithm in this section to compute the solution to the following system of equations:Note that this is a very small change from the previous problem, since the only difference is that has changed by only . How much has the answer changed?Solution: The solution is nowConsidering the small change in the problem, this is a substantial change in the solution.
7 Write a computer code to do the previous two problems.
8 Verify that the following system is diagonally dominant and use the algorithm of this section to find the solution.
9 Use the algorithm of this section to find the solution to this system:Note that the right side here is different from that in the previous problem by only a small amount in the component. Comment on your results here as compared to those in the previous problem.Solution: The solution is nowAgain, this is a very large change in the solution for so modest a change in the problem.
10 Write a computer code to do the previous two problems.
11 Write a code that carries out the tridiagonal solution algorithm, and test it on the following system of equations,where is withand for all . Check your results by computing the residual . What is the largest component (in absolute value) of ? (You could also check your results by using MATLAB's backslash operator to solve the system.)
12 Extend the tridiagonal algorithm to a pentadiagonal matrix, i.e., one with five non‐zero diagonals. Write a program to carry out this solution algorithm, and apply it to the systemCheck your results by again computing the residual vector, or by using MATLAB's backslash operation.Solution: A MATLAB script for doing this is given below. On the example in the exercise it returns the (exact) solution .function [delta, f, x] = pentasol(k,l,d,u,v,b) n = length(d); x = zeros(n,1); d(2) = d(2) - l(2)*u(1)/d(1); u(2) = u(2) - l(2)*v(1)/d(1); b(2) = b(2) - l(2)*b(1)/d(1); for j=3:n l(j) = l(j) - k(3)*u(j-2)/d(j-2); d(j) = d(j) - k(j)*v(j-2)/d(j-2); b(j) = b(j) - k(j)*b(j-2)/d(j-2); d(j) = d(j) - l(j)*u(j-1)/d(j-1); if j < n u(j) = u(j) - l(j)*v(j-1)/d(j-1); end b(j) = b(j) - l(j)*b(j-1)/d(j-1); end delta = d; f = b; x = f; % x(n) = f(n)/d(n); x(n-1) = (b(n-1) - u(n-1)*x(n))/d(n-1); for j=(n-2):(-1):1 x(j) = (b(j) - u(j)*x(j+1) - v(j)*x(j+2))/d(j) end
13 Consider the family of tridiagonal problems defined by the matrix , withand a randomly defined right‐hand‐side vector. (Use rand to generate the random vectors.) Solve the system over the range ; use the appropriate timing functions to estimate the CPU time required for each case, and plot the result as a function of . Comment on your results. (You will probably want to use a semilog plot.)Solution: I got the plot in Fig. 2.5. While this is a “noisy” plot, it is very much generally a logarithmic curve, which suggests the actual timing numbers are a straight line, which is what we would expect, given that the cost of doing the solution is linear in the size of the matrix.Figure 2.5 Estimated timing cost for Problem 13, semilog scale.