<?xml version="1.0" encoding="UTF-8"?>

<!--
 * Scilab ( https://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="ja" xml:id="lsq">

    <refnamediv>

        <refname>lsq</refname>

        <refpurpose>norm(X)が最小の A*X=B の線形最小二乗解</refpurpose>

    </refnamediv>

    <refsynopsisdiv>

        <title>呼び出し手順</title>

        <synopsis>
            X = lsq(A, B)
            X = lsq(A, B, tol)
        </synopsis>

    </refsynopsisdiv>

    <refsection>

        <title>引数</title>

        <variablelist>

            <varlistentry>

                <term>A</term>

                <listitem>

                    <para>実数または複素数の (m x n) 行列</para>

                </listitem>

            </varlistentry>

            <varlistentry>

                <term>B</term>

                <listitem>

                    <para>実数または複素数の (m x p) 行列</para>

                </listitem>

            </varlistentry>

            <varlistentry>

                <term>tol</term>

                <listitem>

                    <para>Aの実効ランクを定義するために使用される正のスカラー

                        (Aのピボット操作付きQR分解における最前部にある部分三角行列R11の次数として

                        定義され,条件数の推定値は&lt;= 1/tolとなります.

                        tolのデフォルト値は <literal>sqrt(%eps)</literal>に設定されます )

                    </para>

                </listitem>

            </varlistentry>

            <varlistentry>

                <term>X</term>

                <listitem>

                    <para>実数または複素数の (n x p) 行列</para>

                </listitem>

            </varlistentry>

        </variablelist>

    </refsection>

    <refsection>

        <title>説明</title>

        <para>

            <literal>X=lsq(A,B)</literal> は方程式 <literal>A*X=B</literal>の

            最小二乗解の最小ノルムを計算します.

            一方, <literal>X=A \ B</literal>は

            各列に最大<literal>rank(A)</literal>個の非ゼロ要素を有する最小二乗解を計算します.

        </para>

    </refsection>

    <refsection>

        <title>参考文献</title>

        <para>

            <literal>lsq</literal> 関数はLApack 関数 DGELSY (実行列の場合)および

            ZGELSY (複素行列の場合)に基づいています.

        </para>

    </refsection>

    <refsection>

        <title>例</title>

        <programlisting role="example"><![CDATA[
//Build the data
x=(1:10)';
y1=3*x+4.5+3*rand(x,'normal');
y2=1.8*x+0.5+2*rand(x,'normal');
plot2d(x,[y1,y2],[-2,-3])
//Find the linear regression
A=[x,ones(x)];B=[y1,y2];
X=lsq(A,B);
y1e=X(1,1)*x+X(2,1);
y2e=X(1,2)*x+X(2,2);
plot2d(x,[y1e,y2e],[2,3])
//Difference between lsq(A,b) and A\b
A=rand(4,2)*rand(2,3);//a rank 2 matrix
b=rand(4,1);
X1=lsq(A,b)
X2=A\b
[A*X1-b, A*X2-b] //the residuals are the same
 ]]></programlisting>

    </refsection>

    <refsection role="see also">

        <title>参照</title>

        <simplelist type="inline">

            <member>

                <link linkend="backslash">backslash</link>

            </member>

            <member>

                <link linkend="inv">inv</link>

            </member>

            <member>

                <link linkend="pinv">pinv</link>

            </member>

            <member>

                <link linkend="rank">rank</link>

            </member>

        </simplelist>

    </refsection>

</refentry>

