Mercurial > hg > octave-lyh
comparison scripts/polynomial/polyval.m @ 12482:3244c6e0af4a
polynomial/polyval.m: Compute offset/normalization only when needed.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 26 Feb 2011 16:21:02 -0500 |
parents | 97d103fcb6dd |
children | 5e37369ea13c |
comparison
equal
deleted
inserted
replaced
12481:97d103fcb6dd | 12482:3244c6e0af4a |
---|---|
51 | 51 |
52 if (! (isvector (p) || isempty (p))) | 52 if (! (isvector (p) || isempty (p))) |
53 error ("polyval: first argument must be a vector"); | 53 error ("polyval: first argument must be a vector"); |
54 endif | 54 endif |
55 | 55 |
56 if (nargin < 4) | 56 if (nargin > 3) |
57 mu = [0, 1]; | 57 x = (x - mu(1)) / mu(2); |
58 endif | 58 endif |
59 | 59 |
60 if (isempty (x)) | 60 if (isempty (x)) |
61 y = []; | 61 y = []; |
62 return; | 62 return; |
66 y = p; | 66 y = p; |
67 return; | 67 return; |
68 endif | 68 endif |
69 | 69 |
70 n = length (p) - 1; | 70 n = length (p) - 1; |
71 x = (x - mu(1)) / mu(2); | |
72 y = p(1) * ones (size (x)); | 71 y = p(1) * ones (size (x)); |
73 for i = 2:n+1 | 72 for i = 2:n+1 |
74 y = y .* x + p(i); | 73 y = y .* x + p(i); |
75 endfor | 74 endfor |
76 | 75 |