# SOLVE Linear Solver for Double Dimensioned Arrays

SOLVE is a C++ library which implements a linear solver which makes it easy to create doubly-dimensioned arrays and solve associated linear systems.

The purpose of the library is to allow the user to declare a square matrix A of any size, access matrix entries using the usual double indexing formula A[i][j]=value;, and call a linear solver to solve A*x=b using a call like:

```        x = solve ( n, A, b );
```

In C and C++, it can be awkward to set up matrices in a way that makes it easy to access them with the usual two index form, and to pass these matrices back and forth to other functions. This is because, when using the simplest interface to another function, it is necessary that the second dimension, that is, the number of columns, be declared as a fixed integer, not a variable. Such an interface is impossible to use with a general purpose linear solver.

These problems can be overcome by using a data structure known as a pointer to a pointer. However, creating and deleting such objects can be unfamiliar to the average user. This library hides the details behind an object called an R8RMAT, that is, a double precision real (R8) row-major (R) matrix (MAT). A set of functions, with the "r8rmat_" label, are provided to make it easy to create and delete such objects, and more importantly, to solve an associated linear system.

The SOLVE library makes it possible to set up and solve linear systems in a natural way, as long as the user does the following:

• declare the matrix as a "double **" quantity;
• call r8rmat_new() or r8rmat_zero() to create, or create and zero out, the matrix.
• call r8rmat_fs_new() to solve the linear system.
• call r8rmat_delete() to free the matrix memory when no longer needed.

The library can also be useful because:

• it shows the steps involved in a simple Gauss-elimination procedure;
• it can be used to count the number of operations in Gauss-elimination;
• it can be used as a guide for writing a corresponding program in another language;
• its performance can be compared to corresponding versions in Fortran or Matlab;
• it can be used as a starting point for exploring band storage, sparse storage, iterative solutions and other topics in linear algebra.

### Languages:

SOLVE is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

### Related Data and Programs:

ALLOCATABLE_ARRAY, a C++ program which demonstrates how a C++ function can declare a pointer to an array, call a function, which can then allocate it and fill it with data, and then return the allocated and initialized array to the calling function through the argument list.

CPP_ARRAYS, C++ programs which illustrate the use of vectors, matrices and tensors.

LINPACK, a C++ library which solves linear systems for a variety of matrix storage schemes, real or complex arithmetic, and single or double precision. It includes a routine for computing the singular value decomposition (SVD) of a rectangular matrix. The original version of this library is by Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart.

QR_SOLVE, a C++ library which computes the linear least squares (LLS) solution of a rectangular linear system A*x=b.

R8LIB, a C++ library which contains many utility routines using double precision real (R8) arithmetic.

### List of Routines:

• R8RMAT_COPY_NEW makes a new copy of an R8RMAT .
• R8RMAT_DELETE frees the memory set aside by R8RMAT_NEW.
• R8RMAT_FS_NEW factors and solves an R8RMAT system with one right hand side.
• R8RMAT_NEW sets up an R8RMAT of the desired dimensions.
• R8RMAT_ZERO sets up and zeros an R8RMAT of the desired dimensions.
• R8VEC_COPY_NEW copies an R8VEC.
• R8VEC_PRINT prints an R8VEC.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the C++ source codes.

Last revised on 27 May 2014.