CS240 Lab 3
Numerical Analysis
Project Goal:
To solve linear systems and find roots of complicated functions. It introduces you to
the area of numerical analysis.
Topics covered:
Function calls, loops, selection statements, local variables, standard input, command
line arguments, basic printf, two dimensional arrays, solving linear systems, finding
roots
Task 0: Download the Initial Source Files
Download the file
lab3src.tar
and untar it by typing the command.
tar xvf lab3src.tar
The directory
lab3src
contains the initial sources as well as the script testall that will
test all your programs. To build your programs type "make" inside the directory
lab3
src
. Make sure you compile and test your programs in lore.cs.purdue.edu.
Task 1: GaussianJordan Elimination with Partial Pivoting
Write a program that uses the GaussJordan method to solve a linear system, i.e. given
a matrix A and a vector b, find x such that Ax=b.
For example, the system of linear equations
x
1
+ 2x
2
+ 3x
3
= 6
4x
1
+ 5x
2
+ 6x
3
= 15
7x
1
+ 8x
2
+ 10x
3
= 25
can be written as Ax=b in the following way.
 1 2 3  x
1
  6 
 4 5 6  x
2
=  15 
 7 8 10  x
3
  25 
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentFurthermore, we can write this as what's referred to as an augmented matrix.
 1 2 3 6 
 4 5 6 15 
 7 8 10 25 
We then solve by repeatedly performing elementary row operations where row k of
the matrix is replaced by
row
k
+ scalar * row
i
; i and k are arbitrary rows. The goal is
to reduce the matrix to the following form
 1 0 0 x1 
 0 1 0 x2 
 0 0 1 x3 
The algorithm for doing this is as follows:
for each row r[i] of the matrix (i from 1 to n)
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 REGO

Click to edit the document details