annotate scripts/specfun/legendre.m @ 20162:2645f9ef8c88 stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed specfun, special-matrix, testfun, and time script directories. * scripts/specfun/expint.m, scripts/specfun/isprime.m, scripts/specfun/legendre.m, scripts/specfun/primes.m, scripts/specfun/reallog.m, scripts/specfun/realsqrt.m, scripts/special-matrix/gallery.m, scripts/special-matrix/hadamard.m, scripts/special-matrix/hankel.m, scripts/special-matrix/hilb.m, scripts/special-matrix/invhilb.m, scripts/special-matrix/magic.m, scripts/special-matrix/pascal.m, scripts/special-matrix/rosser.m, scripts/special-matrix/toeplitz.m, scripts/special-matrix/vander.m, scripts/special-matrix/wilkinson.m, scripts/testfun/assert.m, scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/fail.m, scripts/testfun/rundemos.m, scripts/testfun/runtests.m, scripts/testfun/speed.m, scripts/time/asctime.m, scripts/time/calendar.m, scripts/time/clock.m, scripts/time/ctime.m, scripts/time/datenum.m, scripts/time/datestr.m, scripts/time/datevec.m, scripts/time/etime.m, scripts/time/is_leap_year.m, scripts/time/now.m, scripts/time/weekday.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Sun, 03 May 2015 17:00:11 -0700
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19099
diff changeset
1 ## Copyright (C) 2000-2015 Kai Habel
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
2 ## Copyright (C) 2008 Marco Caliari
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
3 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
5 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 ## your option) any later version.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
10 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
15 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 ## <http://www.gnu.org/licenses/>.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
19
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10672
diff changeset
21 ## @deftypefn {Function File} {@var{l} =} legendre (@var{n}, @var{x})
7508
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
22 ## @deftypefnx {Function File} {@var{l} =} legendre (@var{n}, @var{x}, @var{normalization})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
23 ## Compute the Legendre function of degree @var{n} and order
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## @var{m} = 0 @dots{} @var{n}.
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ## The value @var{n} must be a real non-negative integer.
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ##
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## @var{x} is a vector with real-valued elements in the range [-1, 1].
7508
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
29 ##
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ## The optional argument @var{normalization} may be one of @qcode{"unnorm"},
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## @qcode{"sch"}, or @qcode{"norm"}. The default if no normalization is given
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## is @qcode{"unnorm"}.
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ##
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
34 ## When the optional argument @var{normalization} is @qcode{"unnorm"}, compute
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
35 ## the Legendre function of degree @var{n} and order @var{m} and return all
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
36 ## values for @var{m} = 0 @dots{} @var{n}. The return value has one dimension
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## more than @var{x}.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
38 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
39 ## The Legendre Function of degree @var{n} and order @var{m}:
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
40 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
41 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
42 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
43 ## P^m_n(x) = (-1)^m (1-x^2)^{m/2}{d^m\over {dx^m}}P_n (x)
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
44 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
45 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
46 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
47 ##
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
48 ## @example
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
49 ## @group
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
50 ## m m 2 m/2 d^m
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
51 ## P(x) = (-1) * (1-x ) * ---- P(x)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
52 ## n dx^m n
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
53 ## @end group
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
54 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
55 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
56 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
57 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
58 ## @noindent
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
59 ## with Legendre polynomial of degree @var{n}:
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
60 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
61 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
62 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
63 ## P(x) = {1\over{2^n n!}}\biggl({d^n\over{dx^n}}(x^2 - 1)^n\biggr)
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
64 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
65 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
66 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
67 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
68 ## @example
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
69 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 ## 1 d^n 2 n
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 ## P(x) = ------ [----(x - 1) ]
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72 ## n 2^n n! dx^n
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
73 ## @end group
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
74 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
75 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
76 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
77 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
78 ## @noindent
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
79 ## @code{legendre (3, [-1.0, -0.9, -0.8])} returns the matrix:
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
80 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
81 ## @example
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
82 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
83 ## x | -1.0 | -0.9 | -0.8
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
84 ## ------------------------------------
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
85 ## m=0 | -1.00000 | -0.47250 | -0.08000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
86 ## m=1 | 0.00000 | -1.99420 | -1.98000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
87 ## m=2 | 0.00000 | -2.56500 | -4.32000
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
88 ## m=3 | 0.00000 | -1.24229 | -3.24000
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
89 ## @end group
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
90 ## @end example
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
91 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
92 ## When the optional argument @code{normalization} is @qcode{"sch"}, compute
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
93 ## the Schmidt semi-normalized associated Legendre function. The Schmidt
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
94 ## semi-normalized associated Legendre function is related to the unnormalized
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
95 ## Legendre functions by the following:
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
96 ##
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
97 ## For Legendre functions of degree @var{n} and order 0:
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
98 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
99 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
100 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
101 ## SP^0_n (x) = P^0_n (x)
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
102 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
103 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
104 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
105 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
106 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
107 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
108 ## 0 0
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
109 ## SP(x) = P(x)
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110 ## n n
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
111 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
112 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
113 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
114 ## @end ifnottex
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
115 ##
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
116 ## For Legendre functions of degree n and order m:
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
117 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
118 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
119 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
120 ## SP^m_n (x) = P^m_n (x)(-1)^m\biggl({2(n-m)!\over{(n+m)!}}\biggl)^{0.5}
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
121 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
122 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
123 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
124 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
125 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
126 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
127 ## m m m 2(n-m)! 0.5
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
128 ## SP(x) = P(x) * (-1) * [-------]
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
129 ## n n (n+m)!
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
130 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
131 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
132 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
133 ## @end ifnottex
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
134 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
135 ## When the optional argument @var{normalization} is @qcode{"norm"}, compute
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
136 ## the fully normalized associated Legendre function. The fully normalized
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
137 ## associated Legendre function is related to the unnormalized Legendre
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
138 ## functions by the following:
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
139 ##
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
140 ## For Legendre functions of degree @var{n} and order @var{m}
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
141 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
142 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
143 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
144 ## NP^m_n (x) = P^m_n (x)(-1)^m\biggl({(n+0.5)(n-m)!\over{(n+m)!}}\biggl)^{0.5}
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
145 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
146 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
147 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
148 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
149 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
150 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
151 ## m m m (n+0.5)(n-m)! 0.5
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
152 ## NP(x) = P(x) * (-1) * [-------------]
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
153 ## n n (n+m)!
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
154 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
155 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
156 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
157 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
158 ## @end deftypefn
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
159
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
160 ## Author: Marco Caliari <marco.caliari@univr.it>
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
161
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
162 function retval = legendre (n, x, normalization)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
163
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
164 persistent warned_overflow = false;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
165
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
166 if (nargin < 2 || nargin > 3)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
167 print_usage ();
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
168 endif
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
169
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
170 if (! isreal (n) || ! isscalar (n) || n < 0 || n != fix (n))
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
171 error ("legendre: N must be a real non-negative integer");
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
172 elseif (! isreal (x) || any (x(:) < -1 | x(:) > 1))
10672
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
173 error ("legendre: X must be real-valued vector in the range -1 <= X <= 1");
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
174 endif
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
175
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
176 if (nargin == 3)
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
177 normalization = lower (normalization);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
178 else
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
179 normalization = "unnorm";
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
180 endif
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
181
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
182 unnorm = false;
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
183 switch (normalization)
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
184 case "unnorm"
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
185 scale = 1;
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
186 unnorm = true;
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
187 case "norm"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
188 scale = sqrt (n+0.5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
189 case "sch"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
190 scale = sqrt (2);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
191 otherwise
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
192 error ('legendre: NORMALIZATION option must be "unnorm", "norm", or "sch"');
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
193 endswitch
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
194
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
195 scale = scale * ones (size (x));
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
196
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
197 ## Based on the recurrence relation below
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
198 ## m m m
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
199 ## (n-m+1) * P (x) = (2*n+1)*x*P (x) - (n+1)*P (x)
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
200 ## n+1 n n-1
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
201 ## http://en.wikipedia.org/wiki/Associated_Legendre_function
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
202
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
203 overflow = false;
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
204 retval = zeros ([n+1, size(x)]);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
205 for m = 1:n
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
206 lpm1 = scale;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
207 lpm2 = (2*m-1) .* x .* scale;
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
208 lpm3 = lpm2;
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
209 for k = m+1:n
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
210 lpm3a = (2*k-1) .* x .* lpm2;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
211 lpm3b = (k+m-2) .* lpm1;
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
212 lpm3 = (lpm3a - lpm3b) / (k-m+1);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
213 lpm1 = lpm2;
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
214 lpm2 = lpm3;
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
215 if (! warned_overflow)
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
216 if ( any (abs (lpm3a) > realmax)
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
217 || any (abs (lpm3b) > realmax)
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
218 || any (abs (lpm3) > realmax))
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
219 overflow = true;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
220 endif
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
221 endif
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
222 endfor
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
223 retval(m,:) = lpm3(:);
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
224 if (unnorm)
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
225 scale *= -(2*m-1);
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
226 else # normalization = "sch" or "norm"
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
227 scale *= (2*m-1) / sqrt ((n-m+1)*(n+m));
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
228 endif
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
229 scale .*= sqrt (1-x.^2);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
230 endfor
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
231
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
232 retval(n+1,:) = scale(:);
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
233
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
234 if (isvector (x))
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
235 ## vector case is special
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
236 retval = reshape (retval, n + 1, length (x));
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
237 endif
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
238
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
239 if (strcmp (normalization, "sch"))
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
240 retval(1,:) ./= sqrt (2);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
241 endif
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
242
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
243 if (overflow && ! warned_overflow)
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8255
diff changeset
244 warning ("legendre: overflow - results may be unstable for high orders");
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
245 warned_overflow = true;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
246 endif
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
247
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
248 endfunction
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
249
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
250
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
251 %!test
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
252 %! result = legendre (3, [-1.0 -0.9 -0.8]);
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
253 %! expected = [
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
254 %! -1.00000 -0.47250 -0.08000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
255 %! 0.00000 -1.99420 -1.98000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
256 %! 0.00000 -2.56500 -4.32000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
257 %! 0.00000 -1.24229 -3.24000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
258 %! ];
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
259 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
260
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
261 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
262 %! result = legendre (3, [-1.0 -0.9 -0.8], "sch");
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
263 %! expected = [
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
264 %! -1.00000 -0.47250 -0.08000
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
265 %! 0.00000 0.81413 0.80833
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
266 %! -0.00000 -0.33114 -0.55771
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
267 %! 0.00000 0.06547 0.17076
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
268 %! ];
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
269 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
270
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
271 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
272 %! result = legendre (3, [-1.0 -0.9 -0.8], "norm");
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
273 %! expected = [
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
274 %! -1.87083 -0.88397 -0.14967
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
275 %! 0.00000 1.07699 1.06932
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
276 %! -0.00000 -0.43806 -0.73778
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
277 %! 0.00000 0.08661 0.22590
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
278 %! ];
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
279 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
280
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
281 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
282 %! result = legendre (151, 0);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
283 %! ## Don't compare to "-Inf" since it would fail on 64 bit systems.
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
284 %! assert (result(end) < -1.7976e308 && all (isfinite (result(1:end-1))));
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
285
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
286 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
287 %! result = legendre (150, 0);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
288 %! ## This agrees with Matlab's result.
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
289 %! assert (result(end), 3.7532741115719e+306, 0.0000000000001e+306);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
290
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
291 %!test
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
292 %! result = legendre (0, 0:0.1:1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
293 %! assert (result, full (ones (1,11)));
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
294
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
295 %!test
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
296 %! ## Test matrix input
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
297 %! result = legendre (3, [-1,0,1;1,0,-1]);
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
298 %! expected(:,:,1) = [-1,1;0,0;0,0;0,0];
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
299 %! expected(:,:,2) = [0,0;1.5,1.5;0,0;-15,-15];
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
300 %! expected(:,:,3) = [1,-1;0,0;0,0;0,0];
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
301 %! assert (result, expected);
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
302
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
303 %!test
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
304 %! result = legendre (3, [-1,0,1;1,0,-1]');
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
305 %! expected(:,:,1) = [-1,0,1;0,1.5,0;0,0,0;0,-15,0];
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
306 %! expected(:,:,2) = [1,0,-1;0,1.5,0;0,0,0;0,-15,0];
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
307 %! assert (result, expected);
10672
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
308
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
309 ## Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
310 %!error legendre ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
311 %!error legendre (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
312 %!error legendre (1,2,3,4)
19099
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
313 %!error <must be a real non-negative integer> legendre (i, [-1, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
314 %!error <must be a real non-negative integer> legendre ([1, 2], [-1, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
315 %!error <must be a real non-negative integer> legendre (-1, [-1, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
316 %!error <must be a real non-negative integer> legendre (1.1, [-1, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
317 %!error <must be real-valued vector> legendre (1, [-1+i, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
318 %!error <in the range -1 .= X .= 1> legendre (1, [-2, 0, 1])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
319 %!error <in the range -1 .= X .= 1> legendre (1, [-1, 0, 2])
55b613e5183d legendre.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
320 %!error <NORMALIZATION option must be> legendre (1, [-1, 0, 1], "badnorm")
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
321