f04 Chapter Contents
f04 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_real_lin_eqn (f04arc)

## 1  Purpose

nag_real_lin_eqn (f04arc) calculates the approximate solution of a set of real linear equations with a single right-hand side, using an $LU$ factorization with partial pivoting.

## 2  Specification

 #include #include
 void nag_real_lin_eqn (Integer n, double a[], Integer tda, const double b[], double x[], NagError *fail)

## 3  Description

Given a set of linear equations, $Ax=b$, the function first computes an $LU$ factorization of $A$ with partial pivoting, $PA=LU$, where $P$ is a permutation matrix, $L$ is lower triangular and $U$ is unit upper triangular. The approximate solution $x$ is found by forward and backward substitution in $Ly=Pb$ and $Ux=y$, where $b$ is the right-hand side.

## 4  References

Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## 5  Arguments

1:     nIntegerInput
On entry: $n$, the order of the matrix A.
Constraint: ${\mathbf{n}}\ge 1$.
2:     a[${\mathbf{n}}×{\mathbf{tda}}$]doubleInput/Output
Note: the $\left(i,j\right)$th element of the matrix $A$ is stored in ${\mathbf{a}}\left[\left(i-1\right)×{\mathbf{tda}}+j-1\right]$.
On entry: the $n$ by $n$ matrix $A$.
On exit: $A$ is overwritten by the lower triangular matrix $L$ and the off-diagonal elements of the upper triangular matrix $U$. The unit diagonal elements of $U$ are not stored.
3:     tdaIntegerInput
On entry: the stride separating matrix column elements in the array a.
Constraint: ${\mathbf{tda}}\ge {\mathbf{n}}$.
4:     b[n]const doubleInput
On entry: the right-hand side vector $b$.
5:     x[n]doubleOutput
On exit: the solution vector $x$.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{tda}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{tda}}\ge {\mathbf{n}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_SINGULAR
The matrix $A$ is singular, possibly due to rounding errors.

## 7  Accuracy

The accuracy of the computed solution depends on the conditioning of the original matrix. For a detailed error analysis see page 107 of Wilkinson and Reinsch (1971).

## 8  Parallelism and Performance

Not applicable.

The time taken by nag_real_lin_eqn (f04arc) is approximately proportional to ${n}^{3}$.

## 10  Example

To solve the set of linear equations $Ax=b$ where
 $A = 33 16 72 -24 -10 -57 -8 -4 -17 and B = -359 281 85 .$

### 10.1  Program Text

Program Text (f04arce.c)

### 10.2  Program Data

Program Data (f04arce.d)

### 10.3  Program Results

Program Results (f04arce.r)