# solve

solve, a C++ code 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 code 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 code 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_test, a C++ code 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_test, C++ codes which illustrate the use of vectors, matrices and tensors.

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

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

### Source Code:

Last revised on 13 April 2020.