This file is indexed.

/usr/share/doc/maxima-doc/html/maxima_64.html is in maxima-doc 5.32.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on January, 10 2014 by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<head>
<title>Maxima 5.32.1 Manual: 64. lsquares</title>

<meta name="description" content="Maxima 5.32.1 Manual: 64. lsquares">
<meta name="keywords" content="Maxima 5.32.1 Manual: 64. lsquares">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
body
{
    color: black;
    background: white; 
    margin-left: 8%;
    margin-right: 13%;
}

h1
{
    margin-left: +8%;
    font-size: 150%;
    font-family: sans-serif
}

h2
{
    font-size: 125%;
    font-family: sans-serif
}

h3
{
    font-size: 100%;
    font-family: sans-serif
}

h2,h3,h4,h5,h6 { margin-left: +4%; }

div.textbox
{
    border: solid;
    border-width: thin;
    /* width: 100%; */
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em
}

div.titlebox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
    background: rgb(200,255,255);
    font-family: sans-serif
}

div.synopsisbox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
     background: rgb(255,220,255);
    /*background: rgb(200,255,255); */
    /* font-family: fixed */
}

pre.example
{
    border: 1px solid gray;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 1em;
    padding-right: 1em;
    /* background: rgb(247,242,180); */ /* kind of sandy */
    /* background: rgb(200,255,255); */ /* sky blue */
    background-color: #F1F5F9; /* light blue-gray */
    /* font-family: "Lucida Console", monospace */
}

div.spacerbox
{
    border: none;
    padding-top: 2em;
    padding-bottom: 2em
}

div.image
{
    margin: 0;
    padding: 1em;
    text-align: center;
}

div.categorybox
{
    border: 1px solid gray;
    padding-top: 0px;
    padding-bottom: 0px;
    padding-left: 1em;
    padding-right: 1em;
    background: rgb(247,242,220);
}


-->
</style>

<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="lsquares"></a>
<a name="SEC307"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_63.html#SEC306" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC308" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima_63.html#SEC304" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_65.html#SEC310" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 64. lsquares </h1>

<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC308">64.1 Introduction to lsquares</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC309">64.2 Functions and Variables for lsquares</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<p><a name="Item_003a-Introduction-to-lsquares"></a>
</p><hr size="6">
<a name="Introduction-to-lsquares"></a>
<a name="SEC308"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC307" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC309" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC307" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC307" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_65.html#SEC310" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 64.1 Introduction to lsquares </h2>

<p><code>lsquares</code> is a collection of functions to implement the method of least squares
to estimate parameters for a model from numerical data.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Statistical estimation} &middot;
@ref{Category: Share packages} &middot;
@ref{Category: Package lsquares}
</div>
</p>
<p><a name="Item_003a-Functions-and-Variables-for-lsquares"></a>
</p><hr size="6">
<a name="Functions-and-Variables-for-lsquares"></a>
<a name="SEC309"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC308" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_65.html#SEC310" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC307" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC307" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_65.html#SEC310" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 64.2 Functions and Variables for lsquares </h2>

<p><a name="Item_003a-lsquares_005festimates"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_estimates</b><i> (<var>D</var>, <var>x</var>, <var>e</var>, <var>a</var>)</i>
<a name="IDX2557"></a>
</dt>
<dt><u>Function:</u> <b>lsquares_estimates</b><i> (<var>D</var>, <var>x</var>, <var>e</var>, <var>a</var>, initial = <var>L</var>, tol = <var>t</var>)</i>
<a name="IDX2558"></a>
</dt>
<dd><p>Estimate parameters <var>a</var> to best fit the equation <var>e</var>
in the variables <var>x</var> and <var>a</var> to the data <var>D</var>,
as determined by the method of least squares.
<code>lsquares_estimates</code> first seeks an exact solution,
and if that fails, then seeks an approximate solution.
</p>
<p>The return value is a list of lists of equations of the form <code>[a = ..., b = ..., c = ...]</code>.
Each element of the list is a distinct, equivalent minimum of the mean square error.
</p>
<p>The data <var>D</var> must be a matrix.
Each row is one datum (which may be called a `record' or `case' in some contexts),
and each column contains the values of one variable across all data.
The list of variables <var>x</var> gives a name for each column of <var>D</var>,
even the columns which do not enter the analysis.
The list of parameters <var>a</var> gives the names of the parameters for which
estimates are sought.
The equation <var>e</var> is an expression or equation in the variables <var>x</var> and <var>a</var>;
if <var>e</var> is not an equation, it is treated the same as <code><var>e</var> = 0</code>.
</p>
<p>Additional arguments to <code>lsquares_estimates</code>
are specified as equations and passed on verbatim to the function <code>lbfgs</code>
which is called to find estimates by a numerical method
when an exact result is not found.
</p>
<p>If some exact solution can be found (via <code>solve</code>),
the data <var>D</var> may contain non-numeric values.
However, if no exact solution is found,
each element of <var>D</var> must have a numeric value.
This includes numeric constants such as <code>%pi</code> and <code>%e</code> as well as literal numbers
(integers, rationals, ordinary floats, and bigfloats).
Numerical calculations are carried out with ordinary floating-point arithmetic,
so all other kinds of numbers are converted to ordinary floats for calculations.
</p>
<p><code>load(lsquares)</code> loads this function.
</p>
<p>See also
<code>lsquares_estimates_exact</code>,
<code>lsquares_estimates_approximate</code>,<br>
<code>lsquares_mse</code>,
<code>lsquares_residuals</code>,
and <code>lsquares_residual_mse</code>.
</p>
<p>Examples:
</p>
<p>A problem for which an exact solution is found.
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
        [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                                  [ 1  1  1 ]
                                  [         ]
                                  [ 3       ]
                                  [ -  1  2 ]
                                  [ 2       ]
                                  [         ]
(%o2)                             [ 9       ]
                                  [ -  2  1 ]
                                  [ 4       ]
                                  [         ]
                                  [ 3  2  2 ]
                                  [         ]
                                  [ 2  2  1 ]
(%i3) lsquares_estimates (
         M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);
                         59        27      10921        107
(%o3)            [[A = - --, B = - --, C = -----, D = - ---]]
                         16        16      1024         32
</pre>
<p>A problem for which no exact solution is found,
so <code>lsquares_estimates</code> resorts to numerical approximation.
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix ([1, 1], [2, 7/4], [3, 11/4], [4, 13/4]);
                                   [ 1  1  ]
                                   [       ]
                                   [    7  ]
                                   [ 2  -  ]
                                   [    4  ]
                                   [       ]
(%o2)                              [    11 ]
                                   [ 3  -- ]
                                   [    4  ]
                                   [       ]
                                   [    13 ]
                                   [ 4  -- ]
                                   [    4  ]
(%i3) lsquares_estimates (
  M, [x,y], y=a*x^b+c, [a,b,c], initial=[3,3,3], iprint=[-1,0]);
(%o3) [[a = 1.387365874920637, b = .7110956639593767, 
                                        c = - .4142705622439105]]
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-lsquares_005festimates_005fexact"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_estimates_exact</b><i> (<var>MSE</var>, <var>a</var>)</i>
<a name="IDX2559"></a>
</dt>
<dd><p>Estimate parameters <var>a</var> to minimize the mean square error <var>MSE</var>,
by constructing a system of equations and attempting to solve them symbolically via <code>solve</code>.
The mean square error is an expression in the parameters <var>a</var>,
such as that returned by <code>lsquares_mse</code>.
</p>
<p>The return value is a list of lists of equations of the form <code>[a = ..., b = ..., c = ...]</code>.
The return value may contain zero, one, or two or more elements.
If two or more elements are returned,
each represents a distinct, equivalent minimum of the mean square error.
</p>
<p>See also
<code>lsquares_estimates</code>,
<code>lsquares_estimates_approximate</code>,
<code>lsquares_mse</code>,
<code>lsquares_residuals</code>,
and <code>lsquares_residual_mse</code>.
</p>
<p>Example:
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
         [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                           [ 1  1  1 ]
                           [         ]
                           [ 3       ]
                           [ -  1  2 ]
                           [ 2       ]
                           [         ]
(%o2)                      [ 9       ]
                           [ -  2  1 ]
                           [ 4       ]
                           [         ]
                           [ 3  2  2 ]
                           [         ]
                           [ 2  2  1 ]
(%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
           5
          ====
          \                 2                         2
           &gt;    ((D + M    )  - C - M     B - M     A)
          /            i, 1          i, 3      i, 2
          ====
          i = 1
(%o3)     ---------------------------------------------
                                5
(%i4) lsquares_estimates_exact (mse, [A, B, C, D]);
                  59        27      10921        107
(%o4)     [[A = - --, B = - --, C = -----, D = - ---]]
                  16        16      1024         32
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-lsquares_005festimates_005fapproximate"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_estimates_approximate</b><i> (<var>MSE</var>, <var>a</var>, initial = <var>L</var>, tol = <var>t</var>)</i>
<a name="IDX2560"></a>
</dt>
<dd><p>Estimate parameters <var>a</var> to minimize the mean square error <var>MSE</var>,
via the numerical minimization function <code>lbfgs</code>.
The mean square error is an expression in the parameters <var>a</var>,
such as that returned by <code>lsquares_mse</code>.
</p>
<p>The solution returned by <code>lsquares_estimates_approximate</code> is a local (perhaps global) minimum
of the mean square error.
For consistency with <code>lsquares_estimates_exact</code>,
the return value is a nested list which contains one element,
namely a list of equations of the form <code>[a = ..., b = ..., c = ...]</code>.
</p>
<p>Additional arguments to <code>lsquares_estimates_approximate</code>
are specified as equations and passed on verbatim to the function <code>lbfgs</code>.
</p>
<p><var>MSE</var> must evaluate to a number when the parameters are assigned numeric values.
This requires that the data from which <var>MSE</var> was constructed
comprise only numeric constants such as <code>%pi</code> and <code>%e</code> and literal numbers
(integers, rationals, ordinary floats, and bigfloats).
Numerical calculations are carried out with ordinary floating-point arithmetic,
so all other kinds of numbers are converted to ordinary floats for calculations.
</p>
<p><code>load(lsquares)</code> loads this function.
</p>
<p>See also
<code>lsquares_estimates</code>,
<code>lsquares_estimates_exact</code>,
<code>lsquares_mse</code>,<br>
<code>lsquares_residuals</code>,
and <code>lsquares_residual_mse</code>.
</p>
<p>Example:
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
         [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                           [ 1  1  1 ]
                           [         ]
                           [ 3       ]
                           [ -  1  2 ]
                           [ 2       ]
                           [         ]
(%o2)                      [ 9       ]
                           [ -  2  1 ]
                           [ 4       ]
                           [         ]
                           [ 3  2  2 ]
                           [         ]
                           [ 2  2  1 ]
(%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
           5
          ====
          \                 2                         2
           &gt;    ((D + M    )  - C - M     B - M     A)
          /            i, 1          i, 3      i, 2
          ====
          i = 1
(%o3)     ---------------------------------------------
                                5
(%i4) lsquares_estimates_approximate (
              mse, [A, B, C, D], iprint = [-1, 0]);
(%o4) [[A = - 3.67850494740174, B = - 1.683070351177813, 
                 C = 10.63469950148635, D = - 3.340357993175206]]
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-lsquares_005fmse"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_mse</b><i> (<var>D</var>, <var>x</var>, <var>e</var>)</i>
<a name="IDX2561"></a>
</dt>
<dd><p>Returns the mean square error (MSE), a summation expression, for the equation <var>e</var>
in the variables <var>x</var>, with data <var>D</var>.
</p>
<p>The MSE is defined as:
</p>
<pre class="example">                    n
                   ====
               1   \                        2
               -    &gt;    (lhs(e ) - rhs(e ))
               n   /           i         i
                   ====
                   i = 1
</pre>
<p>where <var>n</var> is the number of data and <code><var>e</var>[i]</code> is the equation <var>e</var>
evaluated with the variables in <var>x</var> assigned values from the <code>i</code>-th datum, <code><var>D</var>[i]</code>.
</p>
<p><code>load(lsquares)</code> loads this function.
</p>
<p>Example:
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
         [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                           [ 1  1  1 ]
                           [         ]
                           [ 3       ]
                           [ -  1  2 ]
                           [ 2       ]
                           [         ]
(%o2)                      [ 9       ]
                           [ -  2  1 ]
                           [ 4       ]
                           [         ]
                           [ 3  2  2 ]
                           [         ]
                           [ 2  2  1 ]
</pre><pre class="example">(%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
           5
          ====
          \                 2                         2
           &gt;    ((D + M    )  - C - M     B - M     A)
          /            i, 1          i, 3      i, 2
          ====
          i = 1
(%o3)     ---------------------------------------------
                                5
</pre><pre class="example">(%i4) diff (mse, D);
         5
        ====
        \                             2
      4  &gt;    (D + M    ) ((D + M    )  - C - M     B - M     A)
        /           i, 1         i, 1          i, 3      i, 2
        ====
        i = 1
(%o4) ----------------------------------------------------------
                                  5
</pre><pre class="example">(%i5) ''mse, nouns;
               2                 2         9 2               2
(%o5) (((D + 3)  - C - 2 B - 2 A)  + ((D + -)  - C - B - 2 A)
                                           4
           2               2         3 2               2
 + ((D + 2)  - C - B - 2 A)  + ((D + -)  - C - 2 B - A)
                                     2
           2             2
 + ((D + 1)  - C - B - A) )/5
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-lsquares_005fresiduals"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_residuals</b><i> (<var>D</var>, <var>x</var>, <var>e</var>, <var>a</var>)</i>
<a name="IDX2562"></a>
</dt>
<dd><p>Returns the residuals for the equation <var>e</var>
with specified parameters <var>a</var> and data <var>D</var>.
</p>
<p><var>D</var> is a matrix, <var>x</var> is a list of variables,
<var>e</var> is an equation or general expression;
if not an equation, <var>e</var> is treated as if it were <code><var>e</var> = 0</code>.
<var>a</var> is a list of equations which specify values for any free parameters in <var>e</var> aside from <var>x</var>.
</p>
<p>The residuals are defined as:
</p>
<pre class="example">                        lhs(e ) - rhs(e )
                             i         i
</pre>
<p>where <code><var>e</var>[i]</code> is the equation <var>e</var>
evaluated with the variables in <var>x</var> assigned values from the <code>i</code>-th datum, <code><var>D</var>[i]</code>,
and assigning any remaining free variables from <var>a</var>.
</p>
<p><code>load(lsquares)</code> loads this function.
</p>
<p>Example:
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
         [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                                  [ 1  1  1 ]
                                  [         ]
                                  [ 3       ]
                                  [ -  1  2 ]
                                  [ 2       ]
                                  [         ]
(%o2)                             [ 9       ]
                                  [ -  2  1 ]
                                  [ 4       ]
                                  [         ]
                                  [ 3  2  2 ]
                                  [         ]
                                  [ 2  2  1 ]
(%i3) a : lsquares_estimates (
          M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);
                         59        27      10921        107
(%o3)            [[A = - --, B = - --, C = -----, D = - ---]]
                         16        16      1024         32
(%i4) lsquares_residuals (
          M, [z,x,y], (z+D)^2 = A*x+B*y+C, first(a));
                            13    13    13  13  13
(%o4)                      [--, - --, - --, --, --]
                            64    64    32  64  64
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-lsquares_005fresidual_005fmse"></a>
</p><dl>
<dt><u>Function:</u> <b>lsquares_residual_mse</b><i> (<var>D</var>, <var>x</var>, <var>e</var>, <var>a</var>)</i>
<a name="IDX2563"></a>
</dt>
<dd><p>Returns the residual mean square error (MSE) for the equation <var>e</var>
with specified parameters <var>a</var> and data <var>D</var>.
</p>
<p>The residual MSE is defined as:
</p>
<pre class="example">                    n
                   ====
               1   \                        2
               -    &gt;    (lhs(e ) - rhs(e ))
               n   /           i         i
                   ====
                   i = 1
</pre>
<p>where <code><var>e</var>[i]</code> is the equation <var>e</var>
evaluated with the variables in <var>x</var> assigned values from the <code>i</code>-th datum, <code><var>D</var>[i]</code>,
and assigning any remaining free variables from <var>a</var>.
</p>
<p><code>load(lsquares)</code> loads this function.
</p>
<p>Example:
</p>
<pre class="example">(%i1) load (lsquares)$
(%i2) M : matrix (
         [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
                           [ 1  1  1 ]
                           [         ]
                           [ 3       ]
                           [ -  1  2 ]
                           [ 2       ]
                           [         ]
(%o2)                      [ 9       ]
                           [ -  2  1 ]
                           [ 4       ]
                           [         ]
                           [ 3  2  2 ]
                           [         ]
                           [ 2  2  1 ]
(%i3) a : lsquares_estimates (
             M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);

                  59        27      10921        107
(%o3)     [[A = - --, B = - --, C = -----, D = - ---]]
                  16        16      1024         32
(%i4) lsquares_residual_mse (
             M, [z,x,y], (z + D)^2 = A*x + B*y + C, first (a));
                              169
(%o4)                         ----
                              2560
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-plsquares"></a>
</p><dl>
<dt><u>Function:</u> <b>plsquares</b><i> (<var>Mat</var>,<var>VarList</var>,<var>depvars</var>)</i>
<a name="IDX2564"></a>
</dt>
<dt><u>Function:</u> <b>plsquares</b><i> (<var>Mat</var>,<var>VarList</var>,<var>depvars</var>,<var>maxexpon</var>)</i>
<a name="IDX2565"></a>
</dt>
<dt><u>Function:</u> <b>plsquares</b><i> (<var>Mat</var>,<var>VarList</var>,<var>depvars</var>,<var>maxexpon</var>,<var>maxdegree</var>)</i>
<a name="IDX2566"></a>
</dt>
<dd><p>Multivariable polynomial adjustment of a data table by the &quot;least squares&quot;
method. <var>Mat</var> is a matrix containing the data, <var>VarList</var> is a list of variable names (one for each Mat column, but use &quot;-&quot; instead of varnames to ignore Mat columns), <var>depvars</var> is the name of a dependent variable or a list with one or more names of dependent variables (which names should be in <var>VarList</var>), <var>maxexpon</var> is the optional maximum exponent for each independent variable (1 by default), and <var>maxdegree</var> is the optional maximum polynomial degree (<var>maxexpon</var> by default); note that the sum of exponents of each term must be equal or smaller than <var>maxdegree</var>, and if <code>maxdgree = 0</code> then no limit is applied.
</p>
<p>If <var>depvars</var> is the name of a dependent variable (not in a list), <code>plsquares</code> returns the adjusted polynomial. If <var>depvars</var> is a list of one or more dependent variables, <code>plsquares</code> returns a list with the adjusted polynomial(s). The Coefficients of Determination  are displayed in order to inform about the goodness of fit, which ranges from 0 (no correlation) to 1 (exact correlation). These values are also stored in the global variable <var>DETCOEF</var> (a list if <var>depvars</var> is a list).
</p>

<p>A simple example of multivariable linear adjustment:
</p><pre class="example">(%i1) load(&quot;plsquares&quot;)$

(%i2) plsquares(matrix([1,2,0],[3,5,4],[4,7,9],[5,8,10]),
                [x,y,z],z);
     Determination Coefficient for z = .9897039897039897
                       11 y - 9 x - 14
(%o2)              z = ---------------
                              3
</pre>
<p>The same example without degree restrictions:
</p><pre class="example">(%i3) plsquares(matrix([1,2,0],[3,5,4],[4,7,9],[5,8,10]),
                [x,y,z],z,1,0);
     Determination Coefficient for z = 1.0
                    x y + 23 y - 29 x - 19
(%o3)           z = ----------------------
                              6
</pre>
<p>How many diagonals does a N-sides polygon have? What polynomial degree should be used?
</p><pre class="example">(%i4) plsquares(matrix([3,0],[4,2],[5,5],[6,9],[7,14],[8,20]),
                [N,diagonals],diagonals,5);
     Determination Coefficient for diagonals = 1.0
                                2
                               N  - 3 N
(%o4)              diagonals = --------
                                  2
(%i5) ev(%, N=9);   /* Testing for a 9 sides polygon */
(%o5)                 diagonals = 27
</pre>
<p>How many ways do we have to put two queens without they are threatened into a n x n chessboard?
</p><pre class="example">(%i6) plsquares(matrix([0,0],[1,0],[2,0],[3,8],[4,44]),
                [n,positions],[positions],4);
     Determination Coefficient for [positions] = [1.0]
                         4       3      2
                      3 n  - 10 n  + 9 n  - 2 n
(%o6)    [positions = -------------------------]
                                  6
(%i7) ev(%[1], n=8); /* Testing for a (8 x 8) chessboard */
(%o7)                positions = 1288
</pre>
<p>An example with six dependent variables:
</p><pre class="example">(%i8) mtrx:matrix([0,0,0,0,0,1,1,1],[0,1,0,1,1,1,0,0],
                  [1,0,0,1,1,1,0,0],[1,1,1,1,0,0,0,1])$
(%i8) plsquares(mtrx,[a,b,_And,_Or,_Xor,_Nand,_Nor,_Nxor],
                     [_And,_Or,_Xor,_Nand,_Nor,_Nxor],1,0);
      Determination Coefficient for
[_And, _Or, _Xor, _Nand, _Nor, _Nxor] =
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
(%o2) [_And = a b, _Or = - a b + b + a,
_Xor = - 2 a b + b + a, _Nand = 1 - a b,
_Nor = a b - b - a + 1, _Nxor = 2 a b - b - a + 1]
</pre>
<p>To use this function write first <code>load(&quot;lsquares&quot;)</code>.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Package lsquares} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>


<p><a name="Item_003a-minpack"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC307" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_65.html#SEC310" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>root</em> on <em>January, 10 2014</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 </font>
 <br>

</p>
</body>
</html>