Reading and references:
For each of the following exercises create the specified files with your answer(s). Submit your homework using the course submit utility.
2 1 0 | u0 | 1
2 2 -1 | u1 | 0
0 1 2 | u2 | -1
Compare it with the matrix form in the
notes and be sure you can read off the elements of the
vectors a, b, c, and r. Then by hand
calculation ("playing computer"), carry out the steps in the
method triangulate and backsubst. Notice that each
of these methods has one for loop. Show the values at the end of
each pass through each for loop. To show the current
values, copy the lines above as a template and replace the values
of the entries that are changed. For example, in
triangulate, in the first iteration of the loop you have
i = 0. When it reaches the bottom of the loop the
computer has replaced a[1], b[1], and r[1]
and you would write the current status of the system as
2 1 0 | u0 | 1
0 1 -1 | u1 | -1
0 1 2 | u2 | -1
Continue in the same manner and do this for the remaining steps.
Altogether, you should have five new versions of the linear system
plus the original system. Put all of these versions in your
answer file.
You should recognize the steps as standard Gaussian elimination plus back substitution, except that there is no row pivoting and we don't divide to get a one on the diagonal of the upper triangular matrix.
diff = 2*1 + 1*(-1) - 1
Do the same for the remaining lines.
You should recognize the steps as the calculation of the components of the vector A x - r where A x is the product of the original matrix times the vector x.
You should create a main program file solvetd.cc, and a make file Makefile for building your code. The name of the target and executable is solvetd.
Write your main program solvetd.cc so it reads the matrix problem in the format described under operator>> in tridiagsys.html handout, solves it, prints out the solution, checks the answer, and reports the value of eps, the value returned by the check method.
Hints: Your code should be under 25 lines long, not counting comments! To read all the numbers for the linear system, please see what the operator>> does with cin and this class. It is OK to start with an empty tridiagsys, since the process of reading in the numbers will cause it to grow to the right size. To solve the linear system, please look at the solve method. When you write out your answer, you won't be able to use << with the vector class and cout. So you'll need to do it with a for loop, writing out each element u[i] one-by-one. Finally, to tell how many elements there are in a vector, please see the notes on the standard library vector class. It tells you what method to use.
Note that in order to check the answer, you have to keep a copy of the original tridiagonal system, because after you run the solve method, the system is altered so it becomes trivial.
Hand in only Makefile and solvetd.cc. We already have the file tridiagsys.h.