annotate scripts/specfun/legendre.m @ 14363:f3d52523cde1

Use Octave coding conventions in all m-file %!test blocks * wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m, accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m, celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m, cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m, flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m, interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m, isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m, narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m, polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m, randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m, structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m, griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m, get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m, imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m, textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m, duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m, issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m, qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m, bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m, fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m, ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m, news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m, setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m, warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m, pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m, __plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m, colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m, ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m, ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m, orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m, refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m, stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m, deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m, polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m, ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m, ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m, sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m, pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m, sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m, beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m, nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m, realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m, vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m, iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m, median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m, range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m, statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m, betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m, cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m, chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m, empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m, expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m, gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m, hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m, laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m, logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m, lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m, norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m, poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m, tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m, unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m, wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m, bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m, strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m, substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m, asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m, eomday.m, etime.m, is_leap_year.m, now.m: Use Octave coding conventions in all m-file %!test blocks
author Rik <octave@nomad.inbox5.com>
date Mon, 13 Feb 2012 07:29:44 -0800
parents 4d917a6a858b
children 5d3a684236b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12893
diff changeset
1 ## Copyright (C) 2000-2012 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
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
24 ## @var{m} = 0 @dots{} N@. The optional argument, @var{normalization},
7517
f88b720bf254 legendre.m: modified help text.
Ben Abbott <bpabbott@mac.com>
parents: 7508
diff changeset
25 ## may be one of @code{"unnorm"}, @code{"sch"}, or @code{"norm"}.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
26 ## The default is @code{"unnorm"}. The value of @var{n} must be a
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
27 ## non-negative scalar integer.
7508
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
28 ##
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
29 ## If the optional argument @var{normalization} is missing or is
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
30 ## @code{"unnorm"}, compute the Legendre function of degree @var{n} and
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
31 ## order @var{m} and return all values for @var{m} = 0 @dots{} @var{n}.
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
32 ## The return value has one dimension more than @var{x}.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
33 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
34 ## 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
35 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
36 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
37 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
38 ## 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
39 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
40 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
41 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 ##
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
43 ## @example
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
44 ## @group
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
45 ## 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
46 ## P(x) = (-1) * (1-x ) * ---- P(x)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
47 ## n dx^m n
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
48 ## @end group
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
49 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
51 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
52 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
53 ## @noindent
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
54 ## with Legendre polynomial of degree @var{n}:
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
55 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
56 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
57 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
58 ## 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
59 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
60 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
61 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
62 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
63 ## @example
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
64 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 ## 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
66 ## P(x) = ------ [----(x - 1) ]
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 ## n 2^n n! dx^n
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
68 ## @end group
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
69 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
70 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
71 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
72 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
73 ## @noindent
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
74 ## @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
75 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
76 ## @example
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
77 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
78 ## x | -1.0 | -0.9 | -0.8
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
79 ## ------------------------------------
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
80 ## m=0 | -1.00000 | -0.47250 | -0.08000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
81 ## m=1 | 0.00000 | -1.99420 | -1.98000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
82 ## 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
83 ## m=3 | 0.00000 | -1.24229 | -3.24000
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
84 ## @end group
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
85 ## @end example
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
86 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
87 ## If the optional argument @code{normalization} is @code{"sch"},
7508
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
88 ## compute the Schmidt semi-normalized associated Legendre function.
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
89 ## The Schmidt semi-normalized associated Legendre function is related
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
90 ## to the unnormalized Legendre functions by the following:
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
91 ##
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
92 ## For Legendre functions of degree n and order 0:
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
93 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
94 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
95 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
96 ## 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
97 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
98 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
99 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
100 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
101 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
102 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
103 ## 0 0
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
104 ## SP(x) = P(x)
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 ## n n
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
106 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
107 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
108 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
109 ## @end ifnottex
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
110 ##
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
111 ## 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
112 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
113 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
114 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
115 ## 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
116 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
117 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
118 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
119 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
120 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
121 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
122 ## 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
123 ## 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
124 ## n n (n+m)!
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
125 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
126 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
127 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
128 ## @end ifnottex
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
129 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
130 ## If the optional argument @var{normalization} is @code{"norm"},
7508
f501b22c0394 doc fixes for legendre
John W. Eaton <jwe@octave.org>
parents: 7507
diff changeset
131 ## compute the fully normalized associated Legendre function.
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
132 ## The fully normalized associated Legendre function is related
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
133 ## to the unnormalized Legendre functions by the following:
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
134 ##
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
135 ## 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
136 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
137 ## @tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
138 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
139 ## 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
140 ## $$
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
141 ## @end tex
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
142 ## @ifnottex
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
143 ##
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
144 ## @example
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
145 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
146 ## 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
147 ## 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
148 ## n n (n+m)!
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
149 ## @end group
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
150 ## @end example
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
151 ##
11415
e7ed20f87e82 Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents: 10793
diff changeset
152 ## @end ifnottex
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
153 ## @end deftypefn
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
154
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
155 ## Author: Marco Caliari <marco.caliari@univr.it>
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
156
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
157 function retval = legendre (n, x, normalization)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
158
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
159 persistent warned_overflow = false;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
160
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
161 if (nargin < 2 || nargin > 3)
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
162 print_usage ();
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
163 endif
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
164
10672
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
165 if (!isscalar (n) || n < 0 || n != fix (n))
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
166 error ("legendre: N must be a non-negative scalar integer");
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
167 endif
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
168
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
169 if (!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
170 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
171 endif
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
172
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
173 if (nargin == 3)
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
174 normalization = lower (normalization);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
175 else
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
176 normalization = "unnorm";
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
177 endif
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
178
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
179 switch (normalization)
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
180 case "norm"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
181 scale = sqrt (n+0.5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
182 case "sch"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
183 scale = sqrt (2);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
184 case "unnorm"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
185 scale = 1;
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
186 otherwise
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11415
diff changeset
187 error ('legendre: expecting NORMALIZATION option to be "norm", "sch", or "unnorm"');
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
188 endswitch
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
189
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
190 scale = scale * ones (size (x));
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
191
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
192 ## Based on the recurrence relation below
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
193 ## m m m
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
194 ## (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
195 ## n+1 n n-1
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
196 ## http://en.wikipedia.org/wiki/Associated_Legendre_function
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
197
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
198 overflow = false;
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
199 retval = zeros([n+1, size(x)]);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
200 for m = 1:n
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
201 lpm1 = scale;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
202 lpm2 = (2*m-1) .* x .* scale;
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
203 lpm3 = lpm2;
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
204 for k = m+1:n
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
205 lpm3a = (2*k-1) .* x .* lpm2;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
206 lpm3b = (k+m-2) .* lpm1;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
207 lpm3 = (lpm3a - lpm3b)/(k-m+1);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
208 lpm1 = lpm2;
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
209 lpm2 = lpm3;
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
210 if (! warned_overflow)
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
211 if (any (abs (lpm3a) > realmax)
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
212 || any (abs (lpm3b) > realmax)
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
213 || any (abs (lpm3) > realmax))
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
214 overflow = true;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
215 endif
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
216 endif
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
217 endfor
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
218 retval(m,:) = lpm3(:);
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
219 if (strcmp (normalization, "unnorm"))
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
220 scale = -scale * (2*m-1);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
221 else
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
222 ## normalization == "sch" or normalization == "norm"
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
223 scale = scale / sqrt ((n-m+1)*(n+m))*(2*m-1);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
224 endif
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
225 scale = scale .* sqrt(1-x.^2);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
226 endfor
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
227
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
228 retval(n+1,:) = scale(:);
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
229
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
230 if (isvector (x))
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
231 ## vector case is special
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
232 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
233 endif
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
234
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
235 if (strcmp (normalization, "sch"))
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
236 retval(1,:) = retval(1,:) / sqrt (2);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
237 endif
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
238
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
239 if (overflow && ! warned_overflow)
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8255
diff changeset
240 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
241 warned_overflow = true;
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
242 endif
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
243
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
244 endfunction
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
245
12893
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
246
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
247 %!test
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
248 %! result = legendre (3, [-1.0 -0.9 -0.8]);
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
249 %! expected = [
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
250 %! -1.00000 -0.47250 -0.08000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
251 %! 0.00000 -1.99420 -1.98000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
252 %! 0.00000 -2.56500 -4.32000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
253 %! 0.00000 -1.24229 -3.24000
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
254 %! ];
7507
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
255 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
256
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
257 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
258 %! 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
259 %! expected = [
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
260 %! -1.00000 -0.47250 -0.08000
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
261 %! 0.00000 0.81413 0.80833
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
262 %! -0.00000 -0.33114 -0.55771
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
263 %! 0.00000 0.06547 0.17076
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
264 %! ];
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
265 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
266
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
267 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
268 %! 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
269 %! expected = [
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
270 %! -1.87083 -0.88397 -0.14967
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
271 %! 0.00000 1.07699 1.06932
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
272 %! -0.00000 -0.43806 -0.73778
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
273 %! 0.00000 0.08661 0.22590
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
274 %! ];
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
275 %! assert (result, expected, 1e-5);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
276
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
277 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
278 %! result = legendre (151, 0);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
279 %! ## 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
280 %! 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
281
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
282 %!test
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
283 %! result = legendre (150, 0);
bc6573d2fa40 legendre.m: Added normalization and improved stability.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
284 %! ## 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
285 %! 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
286
8255
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
287 %!test
3f1199ad212f legendre.m: Warn once on under/overflow.
Ben Abbott <bpabbott@mac.com>
parents: 7517
diff changeset
288 %! 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
289 %! 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
290
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
291 %!test
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
292 %! 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
293 %! ## Test matrix input
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
294 %! 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
295 %! 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
296 %! 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
297 %! assert (result, expected);
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
298
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
299 %!test
72ffa81a68d4 legendre.m: Allow ND-array inputs (Bug #33526).
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
300 %! 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
301 %! 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
302 %! 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
303 %! assert (result, expected);
10672
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
304
1cd7c39a96ee legendre.m: Orient row vector correctly (bug #29997).
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
305 %% Check correct invocation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
306 %!error legendre ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
307 %!error legendre (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
308 %!error legendre (1,2,3,4)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
309 %!error legendre ([1, 2], [-1, 0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
310 %!error legendre (-1, [-1, 0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
311 %!error legendre (1.1, [-1, 0, 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, [-1+i, 0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
313 %!error legendre (1, [-2, 0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
314 %!error legendre (1, [-1, 0, 2])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
315 %!error legendre (1, [-1, 0, 1], "badnorm")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
316