Homework # 2 Due Feb 3 in class
Note: You must turn in
if you are using PC-Matlab
(1) a labeled, virus free disk with directory hw# containing 2 m-files for parts (1) and (2). I will run these m-files and read your output.
(2) a hard copy of the source code files and and all graphs.
If you use C++,
(1) turn in all your files on a disk and
(2) a hard copy of the source code files and and all graphs.
From class, we have discussed how to solve a system of linear equations AX = B where the matrix A is a tridiagonal matrix. That is, all entries are zero except the main diagonal as well as the super diagonal and subdiagonal. We used both C++ and PC-Matlab to solve such a system.
Use C++ or PC-Matlab to do the following.
(1) Find the solution of a system EX = B where E is a tridiagonal matrix where the diagonal D has all 3's on it, all 1's on the superdiagonal, and all 2's on the subdiagonal and zeroes elsewhere where E is 30x30. Also B is 30x1 and consists of 1, 2, 3, ..., 30. If you use MatLab, you can write N = 30; D= 3*ones(N,1); etc.
(2) We wish to approximate the solution to the differential equation
y'' + y = sin(x), y(0) = 1, y(pi/2) = 0. This requires the solving of AX = B where A is a tridiagonal matrix.
or
First we need to determine what A and B are. Then from this, we can determine Sup, D, Sub, and B as was discussed in class and also mentioned in trisys.m in PC-Matlab. Study p . 641 to determine what A and B are. DO NOT TRY TO WRITE THE ALGORITHM 11.3 discussed on pages 641-642. Do not reinvent the wheel. Use the programs from the Web that I just mentioned. Note h = (b-a)/(N+1) where a = 0, b = pi/2, and N = number of interior points of [a,b]. Use N = 500. Then xi = a + ih, i = 0, 1, ..., N + 1. We will solve for wi where wi = approximation at xi where i = 1,...,N. Observe that we know x1 and xN+1.
disp(' x Approx Exact')
disp(' ')
disp(Short)
Caution: C = A*B will find the matrix product of 2 matrices whereas E= A.*B finds pointwise product of the elements of the matrices A and B.