* Bug #13810 fixed - householder(v, k*v) returned column of %nan. Input parameters...
[scilab.git] / scilab / modules / linear_algebra / help / en_US / factorization / householder.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) 2008 - INRIA
5  * Copyright (C) 2015 - Samuel GOUGEON
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15  -->
16 <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="householder">
17     <refnamediv>
18         <refname>householder</refname>
19         <refpurpose>Householder orthogonal reflexion matrix</refpurpose>
20     </refnamediv>
21     <refsynopsisdiv>
22         <title>Calling Sequence</title>
23         <synopsis>         householder         // demo</synopsis>
24         <synopsis> u     = householder(v [,w])</synopsis>
25         <synopsis>[u, H] = householder(v [,w])</synopsis>
26     </refsynopsisdiv>
27     <refsection role="arguments">
28         <title>Arguments</title>
29         <variablelist>
30             <varlistentry>
31                 <term>v</term>
32                 <listitem>
33                     <para>real or complex column vector</para>
34                 </listitem>
35             </varlistentry>
36             <varlistentry>
37                 <term>w</term>
38                 <listitem>
39                     <para>
40                         real or complex column vector with same size as <literal>v</literal>.
41                         Default value is <literal>eye(v)</literal> ((Ox) axis).
42                     </para>
43                 </listitem>
44             </varlistentry>
45             <varlistentry>
46                 <term>u</term>
47                 <listitem>
48                     <para>
49                         unit vector lying in the <literal>(v,w)</literal> plane and orthogonal
50                         to the bisectrix of <literal>(v,w)</literal>.
51                         Column of size(v) of real or complex numbers.
52                     </para>
53                 </listitem>
54             </varlistentry>
55             <varlistentry>
56                 <term>H</term>
57                 <listitem>
58                     <para>
59                         Orthogonal Householder reflexion matrix: <literal>H= eye() - 2*u*u'</literal>.
60                         <varname>H</varname> is such that <literal>inv(H)==H</literal>,
61                         <literal>H'==H</literal>, and <literal>det(H)==-1</literal>.
62                     </para>
63                     <para>
64                         If <varname>v</varname> and <varname>w</varname> are real,
65                         <literal>H*v</literal> is proportional to <varname>w</varname>.
66                     </para>
67                 </listitem>
68             </varlistentry>
69         </variablelist>
70     </refsection>
71     <refsection role="description">
72         <title>Description</title>
73         <para>
74             <literal>householder(..)</literal> computes the unit vector <varname>u</varname>
75             lying in the <literal>(v,w)</literal> plane and orthogonal to the bisectrix of
76             <literal>(v,w)</literal>.
77         </para>
78         <para>
79             If <varname>v</varname> and <varname>w</varname> are proportional:
80             <itemizedlist>
81                 <listitem>
82                     <para>
83                         If they are opposite, <literal>u= v/|v|</literal> is returned.
84                     </para>
85                 </listitem>
86                 <listitem>
87                     If they are real and have the same direction, <varname>u</varname> is set
88                     in the (xOy) plane with a priori <literal>u(1)>0</literal>, and orthogonal to
89                     <varname>v</varname> (<literal>u'*v==0</literal>). However,
90                     <itemizedlist>
91                         <listitem>
92                             If they are along (Ox), <literal>u = (Oy+)</literal> is returned instead.
93                         </listitem>
94                         <listitem>
95                             If <varname>v</varname> and <varname>w</varname> are scalars with same
96                             signs, the orthogonal sub-space is restricted to <literal>{0}</literal>
97                             that can't be normalized:
98                             <varname>u</varname> and <varname>H</varname> are then set to
99                             <literal>%nan</literal>.
100                         </listitem>
101                     </itemizedlist>
102                 </listitem>
103             </itemizedlist>
104         </para>
105         <para>
106             If the related reflexion matrix <varname>H</varname> is computed, for any point A
107             of column coordinates <literal>a</literal>, <literal>H*a</literal> are the coordinates of
108             the reflected image of A on P.
109         </para>
110         <note>
111             If <varname>v</varname> or/and <varname>w</varname> are in row, they are priorly
112             transposed into columns.
113         </note>
114         <warning>
115             If <varname>v</varname> or/and <varname>w</varname> are <literal>[]</literal>,
116             <literal>[]</literal> is returned for <varname>u</varname> and <varname>H</varname>.
117         </warning>
118     </refsection>
119     <refsection role="examples">
120         <title>Examples</title>
121         <programlisting role="example"><![CDATA[
122 a = [ rand(1,1) 0  0 ]';
123 [ra hm] = householder(a);
124 [a ra hm*a ]
125 norm(ra)
126
127 b = rand(3,1);
128 [rb, hm] = householder(b);
129 [b rb eye(b) clean(hm*b) ]
130 norm(rb)
131
132 [rb2b, hm] = householder(b, 2*b);
133 [b rb2b clean(hm*b ./ b) ]  // last column must be uniform
134 norm(rb2b)                  // must be 1
135
136 c = rand(3,1);
137 [rbc, hm] = householder(b,c);
138 norm(rbc)          // must be 1
139 hm*b ./c           // must be uniform
140
141 d = b + %i*c;
142 e = rand(3,1) + %i*rand(3,1);
143 [rde, hm] = householder(d,e);
144 norm(rbc)               // must be 1
145 clean(inv(hm) - hm)     // must be zeros(3,3)
146 clean(hm' - hm)         // must be zeros(3,3)
147 clean(det(hm))          // must be -1
148  ]]></programlisting>
149         
150         <para>APPLICATION : Reflected image of an object</para>
151         <programlisting role="example"><![CDATA[
152 // (OA) = [0 0 1] is reflected in O into (OB) = [ 1 1 0.3 ]:
153 [n, H] = householder([0 0 1]', [ 1 1 0.3 ]');
154 // "n" is the unit vector orthogonal to the reflecting plane
155
156 // Emitting object (feature from shell demo):
157 u = linspace(0,2*%pi,40);
158 v = linspace(0,2*%pi,20);
159 Xe = (cos(u).*u)'*(1+cos(v)/2)+10;
160 Ye = (u/2)'*sin(v);
161 Ze = (sin(u).*u)'*(1+cos(v)/2);
162
163 // Reflected object:
164 Pe = [ Xe(:)' ; Ye(:)' ; Ze(:)'];
165 Pr = H*Pe;
166 Xr = matrix(Pr(1,:),40,-1);
167 Yr = matrix(Pr(2,:),40,-1);
168 Zr = matrix(Pr(3,:),40,-1);
169
170 // Reflecting plane containing O: n(1).x + n(2).y + n(3).z = 0
171 //   Sampling space:
172 x = linspace(min([Xe(:);Xr(:)]), max([Xe(:);Xr(:)]),20);
173 y = linspace(min([Ye(:);Yr(:)]), max([Ye(:);Yr(:)]),20);
174 [X, Y] = meshgrid(x,y);
175 //   Generating the mirror:
176 deff("z = mirror(x,y,n)","z = -n(1)/n(3)*x - n(2)/n(3)*y")
177 Zm = mirror(X,Y,n);
178
179 // Plotting:
180 clf
181 drawlater
182 f = gcf();
183 f.color_map = [ 0.8 0.8 0.8 ; jetcolormap(100)];
184 surf(Xe,Ye,Ze)
185 surf(X,Y,Zm)
186 surf(Xr,Yr,Zr)
187 a = gca();
188 a.isoview = "on";
189 a.rotation_angles = [74 123];
190 a.children.color_flag = 0;
191 a.children.color_mode = 0;
192 a.children(1).foreground = color("red");
193 a.children(2).foreground = 1;
194 a.children(3).foreground = color("green");
195 drawnow
196  ]]></programlisting>
197         <scilab:image>
198             householder();
199         </scilab:image>
200     </refsection>
201     <refsection role="see also">
202         <title>See Also</title>
203         <simplelist type="inline">
204             <member>
205                 <link linkend="qr">qr</link>
206             </member>
207             <member>
208                 <link linkend="givens">givens</link>
209             </member>
210         </simplelist>
211     </refsection>
212     <refsection role="history">
213         <title>History</title>
214         <revhistory>
215             <revision>
216                 <revnumber>6.0</revnumber>
217                 <revdescription>
218                     <para>Householder reflexion matrix added as second output parameter.
219                         Demo householder() added. Help page reviewed.
220                     </para>
221                 </revdescription>
222             </revision>
223         </revhistory>
224     </refsection>
225 </refentry>