[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Change to vander.m
From: |
John W. Eaton |
Subject: |
Change to vander.m |
Date: |
Tue, 15 Jan 2008 16:43:21 -0500 |
On 15-Jan-2008, Thomas Weber wrote:
| I'd like to propose the attached patch to vander.m.
|
| Advantage: it's faster for large arguments (a vector size of 3 has a
| comparable speed).
|
| Disadvantages: slower for length(c) == 2 and it needs more memory
| (although if the memory needs start to be a problem, the for-loop in the
| current implementation will hit even harder).
|
| Thomas
| ? plot/.hg
| Index: special-matrix/vander.m
| ===================================================================
| RCS file: /cvs/octave/scripts/special-matrix/vander.m,v
| retrieving revision 1.25
| diff -u -r1.25 vander.m
| --- special-matrix/vander.m 12 Oct 2007 21:27:26 -0000 1.25
| +++ special-matrix/vander.m 15 Jan 2008 20:23:18 -0000
| @@ -58,13 +58,17 @@
|
| if (isvector (c))
| n = length (c);
| - retval = zeros (n, n);
| - j = 1:n;
| - for i = 1:n
| - retval(i,:) = c(i) .^ (n - j);
| - endfor
| + N = ones(n,1) * [n-1:-1:0];
| + C = c(:) * ones(1,n);
| + retval = C .^ N;
Is there any need for the variables N and C? why not just write
retval = (c(:) * ones (1, n)) .^ (ones (n, 1) * (n-1:-1:0));
?
I made this change.
Thanks,
jwe