## 1Purpose

f07adf computes the $LU$ factorization of a real $m$ by $n$ matrix.

## 2Specification

Fortran Interface
 Subroutine f07adf ( m, n, a, lda, ipiv, info)
 Integer, Intent (In) :: m, n, lda Integer, Intent (Out) :: ipiv(min(m,n)), info Real (Kind=nag_wp), Intent (Inout) :: a(lda,*)
#include <nag.h>
 void f07adf_ (const Integer *m, const Integer *n, double a[], const Integer *lda, Integer ipiv[], Integer *info)
The routine may be called by the names f07adf, nagf_lapacklin_dgetrf or its LAPACK name dgetrf.

## 3Description

f07adf forms the $LU$ factorization of a real $m$ by $n$ matrix $A$ as $A=PLU$, where $P$ is a permutation matrix, $L$ is lower triangular with unit diagonal elements (lower trapezoidal if $m>n$) and $U$ is upper triangular (upper trapezoidal if $m). Usually $A$ is square $\left(m=n\right)$, and both $L$ and $U$ are triangular. The routine uses partial pivoting, with row interchanges.

## 4References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1: $\mathbf{m}$Integer Input
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{m}}\ge 0$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
3: $\mathbf{a}\left({\mathbf{lda}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $m$ by $n$ matrix $A$.
On exit: the factors $L$ and $U$ from the factorization $A=PLU$; the unit diagonal elements of $L$ are not stored.
4: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f07adf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
5: $\mathbf{ipiv}\left(\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)\right)$Integer array Output
On exit: the pivot indices that define the permutation matrix. At the $\mathit{i}$th step, if ${\mathbf{ipiv}}\left(\mathit{i}\right)>\mathit{i}$ then row $\mathit{i}$ of the matrix $A$ was interchanged with row ${\mathbf{ipiv}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$. ${\mathbf{ipiv}}\left(i\right)\le i$ indicates that, at the $i$th step, a row interchange was not required.
6: $\mathbf{info}$Integer Output
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\mathbf{info}}<0$
If ${\mathbf{info}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{info}}>0$
Element $〈\mathit{\text{value}}〉$ of the diagonal is exactly zero. The factorization has been completed, but the factor $U$ is exactly singular, and division by zero will occur if it is used to solve a system of equations.

## 7Accuracy

The computed factors $L$ and $U$ are the exact factors of a perturbed matrix $A+E$, where
 $E ≤ c minm,n ε P L U ,$
$c\left(n\right)$ is a modest linear function of $n$, and $\epsilon$ is the machine precision.

## 8Parallelism and Performance

f07adf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The total number of floating-point operations is approximately $\frac{2}{3}{n}^{3}$ if $m=n$ (the usual case), $\frac{1}{3}{n}^{2}\left(3m-n\right)$ if $m>n$ and $\frac{1}{3}{m}^{2}\left(3n-m\right)$ if $m.
A call to this routine with $m=n$ may be followed by calls to the routines:
• f07aef to solve $AX=B$ or ${A}^{\mathrm{T}}X=B$;
• f07agf to estimate the condition number of $A$;
• f07ajf to compute the inverse of $A$.
The complex analogue of this routine is f07arf.

## 10Example

This example computes the $LU$ factorization of the matrix $A$, where
 $A= 1.80 2.88 2.05 -0.89 5.25 -2.95 -0.95 -3.80 1.58 -2.69 -2.90 -1.04 -1.11 -0.66 -0.59 0.80 .$