<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 *
 * 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="balanc">
    <refnamediv>
        <refname>balanc</refname>
        <refpurpose>matrix or pencil balancing</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>[Ab,X]=balanc(A)
            [Eb,Ab,X,Y]=balanc(E,A)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>A:  </term>
                <listitem>
                    <para>a real square matrix</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>X:  </term>
                <listitem>
                    <para>a real square invertible matrix</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>E:  </term>
                <listitem>
                    <para>
                        a real square matrix (same dimension as <literal>A</literal>)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>Y:  </term>
                <listitem>
                    <para>a real square invertible matrix.</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            Balance a square matrix to improve
            its condition number.
        </para>
        <para>
            <literal>[Ab,X] = balanc(A)</literal> finds a similarity transformation
            <literal>X</literal> such that
        </para>
        <para>
            <literal>Ab = inv(X)*A*X</literal> has approximately equal row and column norms.
        </para>
        <para>
            For matrix pencils,balancing is done for improving the
            generalized eigenvalue problem.
        </para>
        <para>
            <literal>[Eb,Ab,X,Y] = balanc(E,A)</literal> returns left and right transformations <literal>X</literal> and <literal>Y</literal>
            such that <literal>Eb=inv(X)*E*Y,  Ab=inv(X)*A*Y</literal>
        </para>
    </refsection>
    <refsection>
        <title>Remark</title>
        <para>
            Balancing is made in the functions <literal>bdiag</literal> and <literal>spec</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
A=[1/2^10,1/2^10;2^10,2^10];
[Ab,X]=balanc(A);
norm(A(1,:))/norm(A(2,:))
norm(Ab(1,:))/norm(Ab(2,:))
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="bdiag">bdiag</link>
            </member>
            <member>
                <link linkend="spec">spec</link>
            </member>
            <member>
                <link linkend="schur">schur</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
