comparison scripts/polynomial/polyreduce.m @ 1025:f558749713f1

[project @ 1995-01-11 20:52:10 by jwe]
author jwe
date Wed, 11 Jan 1995 20:52:10 +0000
parents 3470f1e25a79
children bceff7ccdb79
comparison
equal deleted inserted replaced
1024:56520a75b5b3 1025:f558749713f1
1 function p = polyreduce(p) 1 # Copyright (C) 1995 John W. Eaton
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 the
7 # Free Software Foundation; either version 2, or (at your option) any
8 # later version.
9 #
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Octave; see the file COPYING. If not, write to the Free
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2 18
3 # polyreduce(c) 19 function p = polyreduce (p)
20
21 # usage: polyreduce(c)
22 #
4 # Reduces a polynomial coefficient vector to a minimum number of terms, 23 # Reduces a polynomial coefficient vector to a minimum number of terms,
5 # i.e. it strips off any leading zeros. 24 # i.e. it strips off any leading zeros.
6 # 25 #
7 # SEE ALSO: poly, roots, conv, deconv, residue, filter, polyval, polyvalm, 26 # SEE ALSO: poly, roots, conv, deconv, residue, filter, polyval, polyvalm,
8 # polyderiv, polyinteg 27 # polyderiv, polyinteg
9 28
10 # Author: 29 # Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994.
11 # Tony Richardson
12 # amr@mpl.ucsd.edu
13 # June 1994
14 30
15 index = find(p==0); 31 index = find (p == 0);
16 32
17 index = find(index == 1:length(index)); 33 index = find (index == 1:length(index));
18 34
19 if (length(index) == 0) 35 if (length (index) == 0)
20 return; 36 return;
21 endif 37 endif
22 38
23 if(length(p)>1) 39 if(length(p)>1)
24 p = p(index(length(index))+1:length(p)); 40 p = p (index (length (index))+1:length(p));
25 endif 41 endif
26 42
27 if(length(p)==0) 43 if (length (p) == 0)
28 p = 0; 44 p = 0;
29 endif 45 endif
46
30 endfunction 47 endfunction