<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//en">

<!–Converted with LaTeX2HTML 2022 (Released January 1, 2022) –> <HTML lang="en"> <HEAD> <TITLE>Contents of Examples</TITLE>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0"> <META NAME="Generator" CONTENT="LaTeX2HTML v2022">

<LINK REL="STYLESHEET" HREF="rlabp_tex.css">

<LINK REL="previous" HREF="node26_mn.html"> <LINK REL="up" HREF="node19_mn.html"> <LINK REL="next" HREF="node28_mn.html"> </HEAD>

<BODY bgcolor="#ffffff" text="#000000" link="#9944EE" vlink="#0000ff" alink="#00ff00">

<H3><A ID="SECTION00063800000000000000"> Examples</A> </H3>

<P> Now it is time for a few illustrative examples ...

<P> Suppose you are learning about normal-equations, orthogonal transformations, QR decompositions, etc.<A NAME="tex2html7" HREF="footnode_mn.html#foot237" TARGET="footer"><SUP>6</SUP></A> You have read the proper sections in your text(s), and you want to try your hand at it to see if you really understand it.

<P> First you create an over-determined coefficient matrix, 3 parameters, and 5 equations (<code>a</code>). Then you create an observation matrix (<code>b</code>):

<P> <PRE> &gt; a = [3,4,1;0,2,2;0,0,7;zeros(2,3)]; &gt; b = [14;10;21;6;2]; </PRE>

<P> You've just read that the RLaB&nbsp; operator `<code>/code>' solves systems of equations, so you try it out:

<P> <PRE> &gt; x = a b x = 1 2 3 </PRE>

<P> You check the answer (note that this is a contrived problem):

<P> <PRE> &gt; b - a*x -7.11e-15 -1.78e-15 -1.42e-14 6 2 </PRE>

<P> and it looks ``OK''. The residual in the first three rows is near the machine-epsilon<A NAME="tex2html8" HREF="footnode_mn.html#foot504" TARGET="footer"><SUP>7</SUP></A>. Now you wish to follow the example in the text more closely, in an attempt to reinforce your reading. The text has stated that the ``normal equations'' are: <!– MATH (ATA)x = (ATb) –> (<I>A</I><SUP>T</SUP><I>A</I>)<I>x</I> = (<I>A</I><SUP>T</SUP><I>b</I>).

<P> Not having read the chapter on Gaussian elimination, and matrix inverses yet you try:

<P> <PRE> &gt; x = inv (a'*a) * (a'*b) x = 1 2 3 </PRE>

<P> Fortunately, the problem we are working with is not ill-conditioned, otherwise we may have produced a terrible result with the above procedure. If you want to pursue the reasoning behind the previous statement I suggest you read the section ``Linear Systems of Equations''.

<P> Well, this is all too easy, now you want to get dirty, so you move on to orthogonal transformations. You have read about the construction of Householder vectors and reflections; now you would like to try it first-hand. You know that:

<P> <P><!– MATH

P = I - 2(vvT)/(vTv)

–> </P> <DIV ALIGN="CENTER"> <I>P</I> = <I>I</I> - 2(<I>vv</I><SUP>T</SUP>)/(<I>v</I><SUP>T</SUP><I>v</I>) </DIV><P></P>

<P> Where <I>v</I> is the Householder vector used to form the reflection matrix. First you must construct the vector. Your text<A NAME="tex2html9" HREF="footnode_mn.html#foot252" TARGET="footer"><SUP>8</SUP></A> tells you that a good method for constructing the Householder vector is:

<P> <P><!– MATH

v[2 : n] = x[2 : n]/(x[1] + sign(x[1])*| x|2)

–> </P> <DIV ALIGN="CENTER"> <I>v</I>[2 : <I>n</I>] = <I>x</I>[2 : <I>n</I>]/(<I>x</I>[1] + <I>sign</I>(<I>x</I>[1])*| <I>x</I>|<SUB>2</SUB>) </DIV><P></P> <P><!– MATH

v[1] = 1

–> </P> <DIV ALIGN="CENTER"> <I>v</I>[1] = 1 </DIV><P></P>

<P> <PRE> &gt; a = rand(5,2); // Start out with a more difficult [A] &gt; a a = 0.655 0.265 0.129 0.7 0.91 0.95 0.112 0.0918 0.299 0.902 &gt; ac1 = a[;1]; // grab the 1st column of [a] to work with &gt; u = norm (ac1, "2"); // compute the 2-norm of [ac1] &gt; v[2:5] = ac1[2:5] / (ac1[1] + sign (ac1[1])*u) v = 0 0.0705 0.498 0.0611 0.164 &gt; v[1] = 1; &gt; v = v'; // make v a column vector </PRE>

<P> By using the matrix creation, and element referencing features you have generated the vector in 4 commands. We could have used a signal command

<P> <PRE> &gt; v = [ 1 , a[;1][2:5]' / (a[1;1] + sign(a[1;1])*norm(a[;1],"2")) ]' </PRE>

<P> But, this is less than clear. Note that in this case, since we are working with vectors, we only use a single index when subscripting the variables.

<P> Now that we have our Householder vector, we are ready to assemble the Householder reflection (matrix).

<P> <PRE> &gt; P = eye (5,5) - 2*(v*v')/(v'*v) P = -0.558 -0.11 -0.776 -0.0952 -0.255 -0.11 0.992 -0.0547 -0.00671 -0.018 -0.776 -0.0547 0.614 -0.0474 -0.127 -0.0952 -0.00671 -0.0474 0.994 -0.0156 -0.255 -0.018 -0.127 -0.0156 0.958 &gt; P*a -1.17 -1.2 -1.65e-17 0.596 -1.54e-16 0.22 -1.31e-17 0.00217 -5.39e-17 0.662 </PRE>

<P> As you can see it worked out just like they said it would. All the elements of the first column of <I>A</I>, below the diagonal, have been zeroed out<A NAME="tex2html10" HREF="footnode_mn.html#foot260" TARGET="footer"><SUP>9</SUP></A>. In this manner we can proceed to transform <I>A</I> into an upper triangular matrix.

<P>

<P>

<HR>

</BODY> </HTML>