Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyfit.m @ 19790:446c46af4b42 stable
strip trailing whitespace from most source files
* Makefile.am, NEWS, build-aux/common.mk, configure.ac,
doc/Makefile.am, doc/doxyhtml/Makefile.am,
doc/interpreter/Makefile.am, doc/interpreter/arith.txi,
doc/interpreter/audio.txi, doc/interpreter/basics.txi,
doc/interpreter/bugs.txi, doc/interpreter/container.txi,
doc/interpreter/cp-idx.txi, doc/interpreter/data.txi,
doc/interpreter/debug.txi, doc/interpreter/diagperm.txi,
doc/interpreter/diffeq.txi, doc/interpreter/doccheck/README,
doc/interpreter/doccheck/spellcheck, doc/interpreter/emacs.txi,
doc/interpreter/errors.txi, doc/interpreter/eval.txi,
doc/interpreter/expr.txi, doc/interpreter/external.txi,
doc/interpreter/fn-idx.txi, doc/interpreter/func.txi,
doc/interpreter/geometry.txi, doc/interpreter/geometryimages.m,
doc/interpreter/gpl.txi, doc/interpreter/grammar.txi,
doc/interpreter/gui.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/interpimages.m, doc/interpreter/intro.txi,
doc/interpreter/io.txi, doc/interpreter/java.txi,
doc/interpreter/linalg.txi, doc/interpreter/macros.texi,
doc/interpreter/matrix.txi, doc/interpreter/munge-texi.pl,
doc/interpreter/nonlin.txi, doc/interpreter/numbers.txi,
doc/interpreter/obsolete.txi, doc/interpreter/octave-config.1,
doc/interpreter/octave.texi, doc/interpreter/oop.txi,
doc/interpreter/op-idx.txi, doc/interpreter/optim.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/poly.txi, doc/interpreter/preface.txi,
doc/interpreter/quad.txi, doc/interpreter/set.txi,
doc/interpreter/signal.txi, doc/interpreter/sparse.txi,
doc/interpreter/sparseimages.m, doc/interpreter/splineimages.m,
doc/interpreter/stats.txi, doc/interpreter/stmt.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/testfun.txi, doc/interpreter/tips.txi,
doc/interpreter/var.txi, doc/interpreter/vectorize.txi,
doc/liboctave/Makefile.am, doc/liboctave/array.texi,
doc/liboctave/bugs.texi, doc/liboctave/cp-idx.texi,
doc/liboctave/dae.texi, doc/liboctave/diffeq.texi,
doc/liboctave/error.texi, doc/liboctave/factor.texi,
doc/liboctave/fn-idx.texi, doc/liboctave/gpl.texi,
doc/liboctave/install.texi, doc/liboctave/intro.texi,
doc/liboctave/liboctave.texi, doc/liboctave/matvec.texi,
doc/liboctave/nleqn.texi, doc/liboctave/nlfunc.texi,
doc/liboctave/ode.texi, doc/liboctave/optim.texi,
doc/liboctave/preface.texi, doc/liboctave/quad.texi,
doc/liboctave/range.texi, doc/refcard/Makefile.am,
doc/refcard/refcard.tex, etc/HACKING, etc/NEWS.1, etc/NEWS.2,
etc/NEWS.3, etc/OLD-ChangeLogs/ChangeLog,
etc/OLD-ChangeLogs/doc-ChangeLog,
etc/OLD-ChangeLogs/scripts-ChangeLog,
etc/OLD-ChangeLogs/src-ChangeLog, etc/OLD-ChangeLogs/test-ChangeLog,
etc/PROJECTS, etc/README.Cygwin, etc/README.MacOS, etc/README.MinGW,
etc/README.gnuplot, etc/gdbinit, etc/icons/Makefile.am,
examples/@polynomial/end.m, examples/@polynomial/subsasgn.m,
examples/Makefile.am, examples/standalonebuiltin.cc,
libgui/Makefile.am, libgui/qterminal/libqterminal/README,
libgui/qterminal/libqterminal/unix/BlockArray.cpp,
libgui/qterminal/libqterminal/unix/BlockArray.h,
libgui/qterminal/libqterminal/unix/Character.h,
libgui/qterminal/libqterminal/unix/CharacterColor.h,
libgui/qterminal/libqterminal/unix/Emulation.cpp,
libgui/qterminal/libqterminal/unix/Emulation.h,
libgui/qterminal/libqterminal/unix/Filter.cpp,
libgui/qterminal/libqterminal/unix/Filter.h,
libgui/qterminal/libqterminal/unix/History.cpp,
libgui/qterminal/libqterminal/unix/History.h,
libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp,
libgui/qterminal/libqterminal/unix/KeyboardTranslator.h,
libgui/qterminal/libqterminal/unix/LineFont.h,
libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp,
libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h,
libgui/qterminal/libqterminal/unix/Screen.cpp,
libgui/qterminal/libqterminal/unix/Screen.h,
libgui/qterminal/libqterminal/unix/ScreenWindow.cpp,
libgui/qterminal/libqterminal/unix/ScreenWindow.h,
libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp,
libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.h,
libgui/qterminal/libqterminal/unix/Vt102Emulation.h,
libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp,
libgui/qterminal/qterminal/main.cpp,
libgui/src/m-editor/file-editor-tab.cc, libgui/src/octave-gui.cc,
libgui/src/octave-qt-link.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/defun-int.h, libinterp/corefcn/det.cc,
libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/graphics.cc,
libinterp/corefcn/graphics.in.h, libinterp/corefcn/ls-mat5.cc,
libinterp/corefcn/lu.cc, libinterp/corefcn/oct-tex-parser.yy,
libinterp/corefcn/oct-tex-symbols.in, libinterp/corefcn/quadcc.cc,
libinterp/corefcn/zfstream.cc, libinterp/dldfcn/__eigs__.cc,
libinterp/dldfcn/__voronoi__.cc, libinterp/gendoc.pl,
libinterp/genprops.awk, libinterp/mk-errno-list, libinterp/mk-pkg-add,
libinterp/mkbuiltins, libinterp/mkdefs, libinterp/mkdocs,
libinterp/mkops, libinterp/octave-value/ov-java.cc,
libinterp/parse-tree/lex.ll, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/octave.gperf, liboctave/Makefile.am,
liboctave/array/Array.cc, liboctave/array/module.mk,
liboctave/cruft/daspk/datv.f, liboctave/cruft/daspk/dcnst0.f,
liboctave/cruft/daspk/dcnstr.f, liboctave/cruft/daspk/ddasic.f,
liboctave/cruft/daspk/ddasid.f, liboctave/cruft/daspk/ddasik.f,
liboctave/cruft/daspk/ddaspk.f, liboctave/cruft/daspk/ddstp.f,
liboctave/cruft/daspk/ddwnrm.f, liboctave/cruft/daspk/dfnrmd.f,
liboctave/cruft/daspk/dfnrmk.f, liboctave/cruft/daspk/dhels.f,
liboctave/cruft/daspk/dheqr.f, liboctave/cruft/daspk/dinvwt.f,
liboctave/cruft/daspk/dlinsd.f, liboctave/cruft/daspk/dlinsk.f,
liboctave/cruft/daspk/dmatd.f, liboctave/cruft/daspk/dnedd.f,
liboctave/cruft/daspk/dnedk.f, liboctave/cruft/daspk/dnsd.f,
liboctave/cruft/daspk/dnsid.f, liboctave/cruft/daspk/dnsik.f,
liboctave/cruft/daspk/dnsk.f, liboctave/cruft/daspk/dorth.f,
liboctave/cruft/daspk/dslvd.f, liboctave/cruft/daspk/dslvk.f,
liboctave/cruft/daspk/dspigm.f, liboctave/cruft/daspk/dyypnw.f,
liboctave/cruft/dasrt/ddasrt.f, liboctave/cruft/dasrt/drchek.f,
liboctave/cruft/dassl/ddaslv.f, liboctave/cruft/dassl/ddassl.f,
liboctave/cruft/misc/blaswrap.c, liboctave/cruft/misc/module.mk,
liboctave/cruft/odepack/cfode.f, liboctave/cruft/odepack/dlsode.f,
liboctave/cruft/odepack/ewset.f, liboctave/cruft/odepack/intdy.f,
liboctave/cruft/odepack/prepj.f, liboctave/cruft/odepack/sintdy.f,
liboctave/cruft/odepack/slsode.f, liboctave/cruft/odepack/solsy.f,
liboctave/cruft/odepack/ssolsy.f, liboctave/cruft/odepack/stode.f,
liboctave/cruft/odepack/vnorm.f, liboctave/cruft/ranlib/Basegen.doc,
liboctave/cruft/ranlib/README, liboctave/cruft/ranlib/genbet.f,
liboctave/cruft/ranlib/genexp.f, liboctave/cruft/ranlib/gennch.f,
liboctave/cruft/ranlib/gennf.f, liboctave/cruft/ranlib/gennor.f,
liboctave/cruft/ranlib/getsd.f, liboctave/cruft/ranlib/initgn.f,
liboctave/cruft/ranlib/phrtsd.f, liboctave/cruft/ranlib/randlib.fdoc,
liboctave/cruft/ranlib/setsd.f, liboctave/cruft/ranlib/tstgmn.for,
liboctave/cruft/ranlib/tstmid.for, liboctave/cruft/slatec-fn/atanh.f,
liboctave/cruft/slatec-fn/datanh.f,
liboctave/cruft/slatec-fn/xgmainc.f,
liboctave/cruft/slatec-fn/xsgmainc.f, liboctave/numeric/module.mk,
liboctave/operators/mk-ops.awk, liboctave/operators/mx-ops,
liboctave/operators/sparse-mk-ops.awk,
liboctave/operators/sparse-mx-ops, liboctave/operators/vx-ops,
liboctave/util/module.mk, run-octave.in, scripts/@ftp/ftp.m,
scripts/audio/wavread.m, scripts/deprecated/java_convert_matrix.m,
scripts/deprecated/java_debug.m, scripts/deprecated/java_invoke.m,
scripts/deprecated/java_new.m,
scripts/deprecated/java_unsigned_conversion.m,
scripts/deprecated/javafields.m, scripts/deprecated/javamethods.m,
scripts/deprecated/shell_cmd.m, scripts/general/accumarray.m,
scripts/general/display.m, scripts/general/fieldnames.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/isa.m,
scripts/general/methods.m, scripts/general/sortrows.m,
scripts/geometry/convhull.m, scripts/geometry/delaunay.m,
scripts/geometry/delaunay3.m, scripts/geometry/delaunayn.m,
scripts/geometry/griddata.m, scripts/geometry/griddatan.m,
scripts/geometry/voronoi.m, scripts/geometry/voronoin.m,
scripts/gui/guihandles.m, scripts/gui/inputdlg.m,
scripts/gui/listdlg.m, scripts/gui/msgbox.m, scripts/gui/questdlg.m,
scripts/gui/uigetfile.m, scripts/gui/waitbar.m, scripts/gui/warndlg.m,
scripts/help/doc.m, scripts/help/help.m, scripts/help/type.m,
scripts/image/bone.m, scripts/image/cmpermute.m,
scripts/image/cmunique.m, scripts/image/colorcube.m,
scripts/image/colormap.m, scripts/image/contrast.m,
scripts/image/gray2ind.m, scripts/image/image.m,
scripts/image/imshow.m, scripts/image/ind2gray.m, scripts/image/jet.m,
scripts/image/rgb2ntsc.m, scripts/image/spinmap.m,
scripts/io/importdata.m, scripts/io/strread.m, scripts/io/textread.m,
scripts/io/textscan.m, scripts/java/java_get.m,
scripts/java/java_set.m, scripts/java/javaaddpath.m,
scripts/java/javaclasspath.m, scripts/java/javamem.m,
scripts/linear-algebra/linsolve.m, scripts/linear-algebra/qzhess.m,
scripts/miscellaneous/debug.m, scripts/miscellaneous/desktop.m,
scripts/miscellaneous/dir.m, scripts/miscellaneous/dos.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/fact.m,
scripts/miscellaneous/getappdata.m, scripts/miscellaneous/inputname.m,
scripts/miscellaneous/license.m, scripts/miscellaneous/ls_command.m,
scripts/miscellaneous/run.m, scripts/miscellaneous/setfield.m,
scripts/miscellaneous/unix.m, scripts/miscellaneous/ver.m,
scripts/mk-pkg-add, scripts/mkdoc.pl,
scripts/optimization/fminsearch.m, scripts/optimization/optimset.m,
scripts/optimization/sqp.m, scripts/pkg/pkg.m,
scripts/pkg/private/create_pkgadddel.m,
scripts/pkg/private/fix_depends.m, scripts/pkg/private/install.m,
scripts/plot/appearance/axis.m, scripts/plot/appearance/box.m,
scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m,
scripts/plot/appearance/datetick.m, scripts/plot/appearance/grid.m,
scripts/plot/appearance/legend.m, scripts/plot/appearance/orient.m,
scripts/plot/appearance/shading.m, scripts/plot/appearance/text.m,
scripts/plot/appearance/title.m, scripts/plot/appearance/xlabel.m,
scripts/plot/appearance/ylabel.m, scripts/plot/appearance/zlabel.m,
scripts/plot/draw/area.m, scripts/plot/draw/bar.m,
scripts/plot/draw/barh.m, scripts/plot/draw/colorbar.m,
scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m,
scripts/plot/draw/contourf.m, scripts/plot/draw/ellipsoid.m,
scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m,
scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m,
scripts/plot/draw/ezpolar.m, scripts/plot/draw/fill.m,
scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m,
scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m,
scripts/plot/draw/pareto.m, scripts/plot/draw/patch.m,
scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m,
scripts/plot/draw/pie3.m, scripts/plot/draw/plot.m,
scripts/plot/draw/plotyy.m, scripts/plot/draw/private/__bar__.m,
scripts/plot/draw/private/__contour__.m,
scripts/plot/draw/private/__errplot__.m,
scripts/plot/draw/private/__ezplot__.m,
scripts/plot/draw/private/__patch__.m,
scripts/plot/draw/private/__stem__.m, scripts/plot/draw/rectangle.m,
scripts/plot/draw/ribbon.m, scripts/plot/draw/rose.m,
scripts/plot/draw/scatter.m, scripts/plot/draw/scatter3.m,
scripts/plot/draw/semilogx.m, scripts/plot/draw/shrinkfaces.m,
scripts/plot/draw/sombrero.m, scripts/plot/draw/sphere.m,
scripts/plot/draw/stairs.m, scripts/plot/draw/stem.m,
scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m,
scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m,
scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m,
scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m,
scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m,
scripts/plot/util/__gnuplot_drawnow__.m,
scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/axes.m,
scripts/plot/util/clf.m, scripts/plot/util/copyobj.m,
scripts/plot/util/figure.m, scripts/plot/util/gcbo.m,
scripts/plot/util/graphics_toolkit.m, scripts/plot/util/hggroup.m,
scripts/plot/util/meshgrid.m, scripts/plot/util/newplot.m,
scripts/plot/util/print.m,
scripts/plot/util/private/__add_default_menu__.m,
scripts/plot/util/private/__fltk_print__.m,
scripts/plot/util/private/__gnuplot_print__.m,
scripts/plot/util/private/__print_parse_opts__.m,
scripts/plot/util/refreshdata.m, scripts/plot/util/subplot.m,
scripts/polynomial/conv.m, scripts/polynomial/poly.m,
scripts/polynomial/polyeig.m, scripts/polynomial/polyfit.m,
scripts/polynomial/polyval.m,
scripts/polynomial/private/__splinefit__.m,
scripts/polynomial/spline.m, scripts/prefs/prefdir.m,
scripts/prefs/preferences.m, scripts/prefs/private/prefsfile.m,
scripts/prefs/rmpref.m, scripts/signal/freqz.m,
scripts/signal/module.mk, scripts/sparse/eigs.m, scripts/sparse/pcg.m,
scripts/sparse/private/__sprand_impl__.m, scripts/sparse/sprand.m,
scripts/sparse/sprandn.m, scripts/sparse/spy.m, scripts/sparse/svds.m,
scripts/specfun/expint.m, scripts/specfun/factor.m,
scripts/special-matrix/gallery.m, scripts/special-matrix/hankel.m,
scripts/special-matrix/toeplitz.m, scripts/startup/inputrc,
scripts/statistics/base/kurtosis.m, scripts/statistics/base/moment.m,
scripts/statistics/base/qqplot.m, scripts/statistics/base/var.m,
scripts/statistics/distributions/betarnd.m,
scripts/statistics/distributions/binoinv.m,
scripts/statistics/distributions/binopdf.m,
scripts/statistics/distributions/binornd.m,
scripts/statistics/distributions/cauchy_rnd.m,
scripts/statistics/distributions/chi2rnd.m,
scripts/statistics/distributions/discrete_pdf.m,
scripts/statistics/distributions/discrete_rnd.m,
scripts/statistics/distributions/empirical_rnd.m,
scripts/statistics/distributions/exprnd.m,
scripts/statistics/distributions/frnd.m,
scripts/statistics/distributions/gamrnd.m,
scripts/statistics/distributions/geornd.m,
scripts/statistics/distributions/hygernd.m,
scripts/statistics/distributions/kolmogorov_smirnov_cdf.m,
scripts/statistics/distributions/laplace_cdf.m,
scripts/statistics/distributions/laplace_pdf.m,
scripts/statistics/distributions/logistic_cdf.m,
scripts/statistics/distributions/logistic_pdf.m,
scripts/statistics/distributions/lognrnd.m,
scripts/statistics/distributions/nbincdf.m,
scripts/statistics/distributions/nbininv.m,
scripts/statistics/distributions/nbinpdf.m,
scripts/statistics/distributions/nbinrnd.m,
scripts/statistics/distributions/normrnd.m,
scripts/statistics/distributions/poissinv.m,
scripts/statistics/distributions/poissrnd.m,
scripts/statistics/distributions/tinv.m,
scripts/statistics/distributions/trnd.m,
scripts/statistics/distributions/unidcdf.m,
scripts/statistics/distributions/unidpdf.m,
scripts/statistics/distributions/unidrnd.m,
scripts/statistics/distributions/unifrnd.m,
scripts/statistics/distributions/wblrnd.m,
scripts/statistics/models/module.mk,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/strings/base2dec.m, scripts/strings/deblank.m,
scripts/strings/dec2base.m, scripts/strings/dec2bin.m,
scripts/strings/dec2hex.m, scripts/strings/mat2str.m,
scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m,
scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjoin.m, scripts/strings/strsplit.m,
scripts/strings/strtok.m, scripts/strings/strtrim.m,
scripts/strings/strtrunc.m, scripts/strings/substr.m,
scripts/testfun/__run_test_suite__.m, scripts/testfun/speed.m,
scripts/testfun/test.m, scripts/time/asctime.m,
scripts/time/datenum.m, scripts/time/datevec.m,
scripts/time/weekday.m, src/Makefile.am, test/Makefile.am,
test/build-bc-overload-tests.sh, test/build-sparse-tests.sh,
test/jit.tst, test/line-continue.tst: Strip trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 08:26:57 -0500 |
parents | d63878346099 |
children | e5facc6eec13 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17310
diff
changeset
|
1 ## Copyright (C) 1996-2013 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3368 | 19 ## -*- texinfo -*- |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9290
diff
changeset
|
20 ## @deftypefn {Function File} {@var{p} =} polyfit (@var{x}, @var{y}, @var{n}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9290
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{p}, @var{s}] =} polyfit (@var{x}, @var{y}, @var{n}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9290
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{p}, @var{s}, @var{mu}] =} polyfit (@var{x}, @var{y}, @var{n}) |
3368 | 23 ## Return the coefficients of a polynomial @var{p}(@var{x}) of degree |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
24 ## @var{n} that minimizes the least-squares-error of the fit to the points |
14620
cd375519eab0
doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents:
14401
diff
changeset
|
25 ## @code{[@var{x}, @var{y}]}. If @var{n} is a logical vector, it is used |
14401
2bce551c85b6
doc: Correct typo in polyfit docstring.
Rik <octave@nomad.inbox5.com>
parents:
14377
diff
changeset
|
26 ## as a mask to selectively force the corresponding polynomial |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
27 ## coefficients to be used or ignored. |
3418 | 28 ## |
4491 | 29 ## The polynomial coefficients are returned in a row vector. |
30 ## | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
31 ## The optional output @var{s} is a structure containing the following fields: |
3426 | 32 ## |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
33 ## @table @samp |
4491 | 34 ## @item R |
11593
1577c6f80926
Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
35 ## Triangular factor R from the QR@tie{}decomposition. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
36 ## |
4491 | 37 ## @item X |
7501 | 38 ## The Vandermonde matrix used to compute the polynomial coefficients. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
39 ## |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
40 ## @item C |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
41 ## The unscaled covariance matrix, formally equal to the inverse of |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
42 ## @var{x'}*@var{x}, but computed in a way minimizing roundoff error |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
43 ## propagation. |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
44 ## |
4491 | 45 ## @item df |
7501 | 46 ## The degrees of freedom. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
47 ## |
4491 | 48 ## @item normr |
7501 | 49 ## The norm of the residuals. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
50 ## |
4491 | 51 ## @item yf |
7501 | 52 ## The values of the polynomial for each value of @var{x}. |
4491 | 53 ## @end table |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
54 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 ## The second output may be used by @code{polyval} to calculate the |
14620
cd375519eab0
doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents:
14401
diff
changeset
|
56 ## statistical error limits of the predicted values. In particular, the |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
57 ## standard deviation of @var{p} coefficients is given by @* |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
58 ## @code{sqrt (diag (s.C)/s.df)*s.normr}. |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
59 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 ## When the third output, @var{mu}, is present the |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
61 ## coefficients, @var{p}, are associated with a polynomial in |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
62 ## @var{xhat} = (@var{x}-@var{mu}(1))/@var{mu}(2). |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
63 ## Where @var{mu}(1) = mean (@var{x}), and @var{mu}(2) = std (@var{x}). |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
64 ## This linear transformation of @var{x} improves the numerical |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
65 ## stability of the fit. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
66 ## @seealso{polyval, polyaffine, roots, vander, zscore} |
3368 | 67 ## @end deftypefn |
2311 | 68 |
5428 | 69 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312 | 70 ## Created: 13 December 1994 |
71 ## Adapted-By: jwe | |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
72 ## Modified on 20120204 by P. Dupuis; added the ability to specify a |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
73 ## polynomial mask instead of a polynomial degree. |
2312 | 74 |
4491 | 75 function [p, s, mu] = polyfit (x, y, n) |
2325 | 76 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
77 if (nargin < 3 || nargin > 4) |
6046 | 78 print_usage (); |
2261 | 79 endif |
2325 | 80 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
81 if (nargout > 2) |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
82 ## Normalized the x values. |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
83 mu = [mean(x), std(x)]; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
84 x = (x - mu(1)) / mu(2); |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
85 endif |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
86 |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
87 if (! size_equal (x, y)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
88 error ("polyfit: X and Y must be vectors of the same size"); |
2261 | 89 endif |
2325 | 90 |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
91 if (islogical (n)) |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
92 polymask = n; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
93 ## n is the polynomial degree as given the polymask size; m is the |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
94 ## effective number of used coefficients. |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
95 n = length (polymask) - 1; m = sum (polymask) - 1; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
96 else |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
97 if (! (isscalar (n) && n >= 0 && ! isinf (n) && n == fix (n))) |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
98 error ("polyfit: N must be a non-negative integer"); |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
99 endif |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
100 polymask = logical (ones (1, n+1)); m = n; |
2261 | 101 endif |
2325 | 102 |
14110
b8d9530e940e
undo non-documentation changes in changeset 614505385171
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
103 y_is_row_vector = (rows (y) == 1); |
b8d9530e940e
undo non-documentation changes in changeset 614505385171
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
104 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
105 ## Reshape x & y into column vectors. |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
106 l = numel (x); |
9138 | 107 x = x(:); |
108 y = y(:); | |
2325 | 109 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
110 ## Construct the Vandermonde matrix. |
9138 | 111 v = vander (x, n+1); |
2261 | 112 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
113 ## Solve by QR decomposition. |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
114 [q, r, k] = qr (v(:, polymask), 0); |
9138 | 115 p = r \ (q' * y); |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
116 p(k) = p; |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
117 |
17307
4448cc742880
Use '!' not operator rather than '~' in core m-files.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
118 if (n != m) |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
119 q = p; p = zeros (n+1, 1); |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
120 p(polymask) = q; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
121 endif |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
122 |
4491 | 123 if (nargout > 1) |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
124 yf = v*p; |
3105 | 125 |
14110
b8d9530e940e
undo non-documentation changes in changeset 614505385171
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
126 if (y_is_row_vector) |
4491 | 127 s.yf = yf.'; |
128 else | |
129 s.yf = yf; | |
3105 | 130 endif |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
131 s.X = v; |
3091 | 132 |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
133 ## r.'*r is positive definite if X(:, polymask) is of full rank. |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
134 ## Invert it by cholinv to avoid taking the square root of squared |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
135 ## quantities. If cholinv fails, then X(:, polymask) is rank |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
136 ## deficient and not invertible. |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
137 try |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
138 C = cholinv (r.'*r)(k, k); |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
139 catch |
17310
b327c19b6b16
polyfit.m: Replace NaN*ones(...) with direct construction NaN(...).
Rik <rik@octave.org>
parents:
17307
diff
changeset
|
140 C = NaN (m+1, m+1); |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
141 end_try_catch |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
142 |
17307
4448cc742880
Use '!' not operator rather than '~' in core m-files.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
143 if (n != m) |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
144 ## fill matrices if required |
17307
4448cc742880
Use '!' not operator rather than '~' in core m-files.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
145 s.X(:, !polymask) = 0; |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
146 s.R = zeros (n+1, n+1); s.R(polymask, polymask) = r; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
147 s.C = zeros (n+1, n+1); s.C(polymask, polymask) = C; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
148 else |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
149 s.R = r; |
14377
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
150 s.C = C; |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
151 endif |
c87f927d047d
polyfit.m: add the ability to specify the polynomial template.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
14363
diff
changeset
|
152 s.df = l - m - 1; |
4491 | 153 s.normr = norm (yf - y); |
2261 | 154 endif |
155 | |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
156 ## Return a row vector. |
5395 | 157 p = p.'; |
158 | |
2261 | 159 endfunction |
7411 | 160 |
161 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
162 %!shared x |
7411 | 163 %! x = [-2, -1, 0, 1, 2]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
164 %!assert (polyfit (x, x.^2+x+1, 2), [1, 1, 1], sqrt (eps)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
165 %!assert (polyfit (x, x.^2+x+1, 3), [0, 1, 1, 1], sqrt (eps)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
166 %!fail ("polyfit (x, x.^2+x+1)") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
167 %!fail ("polyfit (x, x.^2+x+1, [])") |
7411 | 168 |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
169 ## Test difficult case where scaling is really needed. This example |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
170 ## demonstrates the rather poor result which occurs when the dependent |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
171 ## variable is not normalized properly. |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
172 ## Also check the usage of 2nd & 3rd output arguments. |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
173 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
14620
diff
changeset
|
174 %! x = [ -1196.4, -1195.2, -1194, -1192.8, -1191.6, -1190.4, -1189.2, -1188, ... |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
175 %! -1186.8, -1185.6, -1184.4, -1183.2, -1182]; |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
14620
diff
changeset
|
176 %! y = [ 315571.7086, 315575.9618, 315579.4195, 315582.6206, 315585.4966, ... |
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
14620
diff
changeset
|
177 %! 315588.3172, 315590.9326, 315593.5934, 315596.0455, 315598.4201, ... |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
178 %! 315600.7143, 315602.9508, 315605.1765 ]; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
179 %! [p1, s1] = polyfit (x, y, 10); |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
180 %! [p2, s2, mu] = polyfit (x, y, 10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
181 %! assert (s2.normr < s1.normr); |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
182 |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
183 %!test |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
184 %! x = 1:4; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
185 %! p0 = [1i, 0, 2i, 4]; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
186 %! y0 = polyval (p0, x); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
187 %! p = polyfit (x, y0, numel (p0) - 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
188 %! assert (p, p0, 1000*eps); |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
189 |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
190 %!test |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
191 %! x = 1000 + (-5:5); |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
192 %! xn = (x - mean (x)) / std (x); |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
193 %! pn = ones (1,5); |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
194 %! y = polyval (pn, xn); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
195 %! [p, s, mu] = polyfit (x, y, numel (pn) - 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
196 %! [p2, s2] = polyfit (x, y, numel (pn) - 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
197 %! assert (p, pn, s.normr); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
198 %! assert (s.yf, y, s.normr); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
199 %! assert (mu, [mean(x), std(x)]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
200 %! assert (s.normr/s2.normr < sqrt (eps)); |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
201 |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
202 %!test |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
203 %! x = [1, 2, 3; 4, 5, 6]; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
204 %! y = [0, 0, 1; 1, 0, 0]; |
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
205 %! p = polyfit (x, y, 5); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
206 %! expected = [0, 1, -14, 65, -112, 60] / 12; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
207 %! assert (p, expected, sqrt (eps)); |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
208 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
209 %!error <vectors of the same size> polyfit ([1, 2; 3, 4], [1, 2, 3, 4], 2) |
7500
2df882e69f13
use QR decomposition and normalization for polyfit; normalization for polyval
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
210 |