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