Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyint.m @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | f1d0f506ee78 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1996-2015 John W. Eaton |
6853 | 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. | |
6853 | 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/>. | |
6853 | 18 |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
20 ## @deftypefn {Function File} {} polyint (@var{p}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
21 ## @deftypefnx {Function File} {} polyint (@var{p}, @var{k}) |
6853 | 22 ## Return the coefficients of the integral of the polynomial whose |
20375
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
23 ## coefficients are represented by the vector @var{p}. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
24 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
25 ## The variable @var{k} is the constant of integration, which by default is |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
26 ## set to zero. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
27 ## @seealso{polyder, polyval} |
6853 | 28 ## @end deftypefn |
29 | |
30 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | |
31 ## Created: June 1994 | |
32 ## Adapted-By: jwe | |
33 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
34 function retval = polyint (p, k) |
6853 | 35 |
36 if (nargin < 1 || nargin > 2) | |
37 print_usage (); | |
38 endif | |
39 | |
40 if (nargin == 1) | |
41 k = 0; | |
42 elseif (! isscalar (k)) | |
43 error ("polyint: the constant of integration must be a scalar"); | |
44 endif | |
45 | |
46 if (! (isvector (p) || isempty (p))) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
47 error ("polyint: argument must be a vector"); |
6853 | 48 endif |
49 | |
50 lp = length (p); | |
51 | |
52 if (lp == 0) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
53 retval = []; |
6853 | 54 return; |
7151 | 55 endif |
6853 | 56 |
57 if (rows (p) > 1) | |
58 ## Convert to column vector | |
59 p = p.'; | |
60 endif | |
61 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
62 retval = [(p ./ [lp:-1:1]), k]; |
6853 | 63 |
64 endfunction | |
12854
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
65 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 |
12854
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
67 %!test |
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
68 %! A = [3, 2, 1]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 %! assert (polyint (A), polyint (A,0)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %! assert (polyint (A), polyint (A')); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
71 %! assert (polyint (A), [1, 1, 1, 0]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 %! assert (polyint (A,1), ones (1,4)); |
12854
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
73 |
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
74 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
75 %! A = ones (1,8); |
12854
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
76 %! B = [length(A):-1:1]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
77 %! assert (polyint (A), [1./B, 0]); |
12854
4e9576618df8
codesprint: Wrote 2 tests for polyint.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
78 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
79 %!error polyint () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
80 %!error polyint (ones (2,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
81 |