Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Linear Algebra Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

4.3 Solving Several Systems of Equations

In this section, a slightly more complicated example program is given. This program reads a matrix A from the input stream, continues to read in right-side vectors, b, and solves the system of equations Ax=b until an end of file is reached. To make it more complex, we assume that the matrix A is positive definite symmetric. Such a matrix can be constructed for test purposes, if you'd like to try this program, by choosing a nonsingular matrix X and forming A=XTX.

Here is a description of the main points in the program:

//1

The header files for the input/output stream classes and the positive-definite factorization class are included.

//2

The double precision symmetric matrix A is defined and then read in from standard input.

//3

Here a positive-definite factorization of the matrix A is constructed and given the name fact. For this to work, the matrix A must be, in fact, positive-definite. If not, the results (fact) are invalid.

//4

Here we test to see if all went well. If so, then...

//5

We define a vector b...

//6

We keep reading vectors from standard input until an end-of-file is encountered, and then...

//7

We use the factorization to solve each set of equations Ax=b.

This program can be written without constructing the factorization explicitly by replacing //7 with:

This is not advisable because the factorization must be computed every time through the loop even though it is not changing. Because constructing the factorization is typically the most expensive part of solving a set of equations, the result is a much slower program.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.