Mercurial > hg > octave-lyh
annotate scripts/polynomial/polyvalm.m @ 16207:0467d68ca891
move current_input_line to lexical_feedback class
* input.h, input.cc, lex.h, lex.ll (current_input_line): Declare as
member of lexical_feedback class.
(octave_base_reader::octave_gets, octave_terminal_reader::get_input,
octave_file_reader::get_input, octave_eval_string_reader::get_input):
Don't set current_input_line.
(octave_lexer::read): Set current_input_line.
* oct-parse.in.yy (octave_parser::bison_error): Use
curr_lexer->current_input_line.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 06 Mar 2013 19:39:48 -0500 |
parents | f3d52523cde1 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
2 ## Copyright (C) 2009 Jaroslav Hajek |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
904 | 19 |
3368 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} polyvalm (@var{c}, @var{x}) | |
2311 | 22 ## Evaluate a polynomial in the matrix sense. |
3426 | 23 ## |
3368 | 24 ## @code{polyvalm (@var{c}, @var{x})} will evaluate the polynomial in the |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## matrix sense, i.e., matrix multiplication is used instead of element by |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
26 ## element multiplication as used in @code{polyval}. |
3426 | 27 ## |
3368 | 28 ## The argument @var{x} must be a square matrix. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
29 ## @seealso{polyval, roots, poly} |
5642 | 30 ## @end deftypefn |
1025 | 31 |
3202 | 32 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 33 ## Created: June 1994 |
34 ## Adapted-By: jwe | |
561 | 35 |
2312 | 36 function y = polyvalm (c, x) |
561 | 37 |
3085 | 38 if (nargin != 2) |
6046 | 39 print_usage (); |
561 | 40 endif |
41 | |
4030 | 42 if (! (isvector (c) || isempty (c))) |
3458 | 43 error ("polyvalm: first argument must be a vector"); |
561 | 44 endif |
45 | |
4030 | 46 if (! issquare (x)) |
3458 | 47 error ("polyvalm: second argument must be a square matrix"); |
561 | 48 endif |
49 | |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
50 n = length (c); |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
51 if (n == 0) |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
52 y = zeros (rows (x), class (x)); |
3085 | 53 else |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
54 id = eye (rows (x), class (x)); |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
55 y = c(1) * id; |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
56 for i = 2:n |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
57 y = y * x + c(i) * id; |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
58 endfor |
3085 | 59 endif |
561 | 60 |
61 endfunction | |
7411 | 62 |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
63 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %!assert (! any (polyvalm ([], [1, 2; 3, 4]))(:)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %!assert (polyvalm ([1, 2, 3, 4], [3, -4, 1; -2, 0, 2; -1, 4, -3]), [117, -124, 11; -70, 36, 38; -43, 92, -45]) |
7411 | 66 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 %!error <must be a square matrix> polyvalm ([1, 1, 1], [1, 2; 3, 4; 5, 6]) |
7411 | 68 |