CSS 455     Scientific Programming    C. Jackels

Winter 2012               January 25,  2012

 

Homework Assignment #3

These are to be worked individually.   Each student is to hand in her/his own assignment at the Catalyst Drop Box the HW3.  However, you are expected to communicate with your partner, discuss strategies for solving the problems, etc.  In the end, you are to solve it yourself, and your solution should not be identical to your partner’s.  What is not allowed is for you to jointly solve the set and turn in your collaborative solution.

 

The following are to be completed and handed in electronically in final form by Saturday, February 4, 2011, at 11:59 PM.   The assignment will be accepted up to 24 hours late for 75% credit and up to 48 hrs late for 50% credit.  For each problem hand in whatever is needed for me to understand your work.  This should certainly include a program listing (m-file), the relevant output, and any notes needed to understand your approach.  The notes should all be gathered in one Word document.  The m-files and outputs can either be cut into the Word document or submitted separately as part of the *zip archive.  The m-files and outputs, if submitted separately, need to have file names that identify them as a particular homework problem.  Your name should be on the Word document and in the comments of the code..



Problem 3-1.  Written Homework Assignment.  

 

This algorithm is described in Ch 7 of Turner and in Set3 of the class notes... 

 

 

Consider a small 4 x 4 demo problem of the rat maze.  The maze is given below with the probabilities of finding food on the perimeter:

XX

0

0

XX

1

 

 

0

1

 

 

0

XX

0

0

XX

 

The corner cells are inaccessible and irrelevant.  The probability for any interior cell is given as the average of its four neighbors:

 

Code the solution to this linear equation problem using the Gauss Seidel algorithm and demonstrate that it works:  starting with guesses where the internal cells are: a) all equal to 0.25, or b) all equal to 1.

 

MP2 will build upon this simple model.  See the Setup Notes for this problem.


 

 

The following problems will take the problem we have set up above and solve it using the other methods found in the chapter 7.  These are small test cases, but illustrate the methods with a problem you are familiar with.  In setting these methods up, you need to generate an A matrix for the system of equations Ap = b.  The p vector is a vector of all of the variable probabilities in the problem.  If there are four variables to b e solved for, p would be (4 x 1).  Each row of A contains the coefficients for one of the equations written with only a constant term on the right hand side.  The b vector contains the right hand sides (sometimes zero) for the equations.  Note that A is not the matrix of probabilities pictured above.  The components of A must be determined for each row from the equation for that row.    Make sure you get this step right – the rest of the problem is then easy.  Feel free to use the codes given in Turner or on my slides.

 

Problem 3-2. 

Write a matlab program to solve the test problem using Gaussian elimination without pivoting.

 

Problem 3-3. 
Write a matlab program (see turner’s example, p.239) to solve the test problem above using Gaussian elimination with partial pivoting.

 

Problem 3-4.

Use the built-in lu function to obtain the L and U factors of A and then write the matlab code to use those factors to solve the system of equations by the forward/backward substitution methods by then by  iterative refinement method .

 

Problem 3-5.  Use the reverse slash operator (\) to solve the system of equations directly.