<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 * Copyright (C) 2009 - Digiteo - Michael Baudin
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="lu">
    <refnamediv>
        <refname>lu</refname>
        <refpurpose>LU factorization with pivoting</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>[L,U]= lu(A)
            [L,U,E]= lu(A)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>A</term>
                <listitem>
                    <para>real or complex  matrix (m x n).</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>L</term>
                <listitem>
                    <para> real or complex matrices  (m x min(m,n)).</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>U</term>
                <listitem>
                    <para>real or complex matrices  (min(m,n) x n ).</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>E</term>
                <listitem>
                    <para>a (n x n) permutation matrix.</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <literal>[L,U]= lu(A)</literal> produces two matrices <literal>L</literal> and
            <literal>U</literal> such that <literal>A = L*U</literal> with <literal>U</literal>
            upper triangular and <literal>L</literal> a general matrix without any particular
            structure. In fact, the matrix <literal>A</literal> is factored as <literal>E*A=B*U</literal>
            where the matrix <literal>B</literal> is lower triangular
            and the matrix <literal>L</literal> is computed from <literal>L=E'*B</literal>.
        </para>
        <para>
            If <literal>A</literal> has rank <literal>k</literal>, rows <literal>k+1</literal> to
            <literal>n</literal> of <literal>U</literal> are zero.
        </para>
        <para>
            <literal>[L,U,E]= lu(A)</literal> produces three matrices <literal>L</literal>, <literal>U</literal> and
            <literal>E</literal> such that <literal>E*A = L*U</literal> with
            <literal>U</literal> upper triangular and <literal>E*L</literal> lower
            triangular for a permutation matrix <literal>E</literal>.
        </para>
        <para>
            If <literal>A</literal> is a real matrix, using the function
            <literal>lufact</literal> and  <literal>luget</literal> it is possible to obtain
            the permutation matrices and also when <literal>A</literal> is not full
            rank the column compression of the matrix <literal>L</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Example #1</title>
        <para>
            In the following example, we create the Hilbert matrix of size 4 and
            factor it with A=LU. Notice that the matrix L is not lower triangular.
            To get a lower triangular L matrix, we should have given the
            output argument E to Scilab.
        </para>
        <programlisting role="example"><![CDATA[
a = testmatrix("hilb",4);
[l,u]=lu(a)
norm(l*u-a)
 ]]></programlisting>
    </refsection>
    <refsection>
        <title>Example #2</title>
        <para>
            In the following example, we create the Hilbert matrix of size 4 and
            factor it with EA=LU. Notice that the matrix L is lower triangular.
        </para>
        <programlisting role="example"><![CDATA[
a = testmatrix("hilb",4);
[l,u,e]=lu(a)
norm(l*u-e*a)
 ]]></programlisting>
    </refsection>
    <refsection>
        <title>Example #3</title>
        <para>
            The following example shows how to use the lufact and luget functions.
        </para>
        <programlisting role="example"><![CDATA[
a=rand(4,4);
[l,u]=lu(a)
norm(l*u-a)

[h,rk]=lufact(sparse(a))
[P,L,U,Q]=luget(h);
ludel(h)
P=full(P);
L=full(L);
U=full(U);
Q=full(Q);
norm(P*L*U*Q-a)
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="lufact">lufact</link>
            </member>
            <member>
                <link linkend="luget">luget</link>
            </member>
            <member>
                <link linkend="lusolve">lusolve</link>
            </member>
            <member>
                <link linkend="qr">qr</link>
            </member>
            <member>
                <link linkend="svd">svd</link>
            </member>
        </simplelist>
    </refsection>
    <refsection>
        <title>Used Functions</title>
        <para>
            lu decompositions are based on the Lapack routines DGETRF for real
            matrices and ZGETRF for the complex case.
        </para>
    </refsection>
</refentry>
