annotate scripts/general/linspace.m @ 2709:0f72b0462b51

[project @ 1997-02-20 17:55:40 by jwe]
author jwe
date Thu, 20 Feb 1997 17:55:44 +0000
parents 6243c37ae2c5
children 8b262e771614
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2697
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
1 ## Copyright (C) 1993, 1994, 1995 John W. Eaton
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
2 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
3 ## This file is part of Octave.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
4 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
6 ## under the terms of the GNU General Public License as published by the
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
8 ## later version.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
9 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
13 ## for more details.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
14 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
15 ## You should have received a copy of the GNU General Public License
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
17 ## Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
18
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
19 ## usage: linspace (x1, x2, n)
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
20 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
21 ## Return a vector of n equally spaced points between x1 and x2
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
22 ## inclusive.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
23 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
24 ## If the final argument is omitted, n = 100 is assumed.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
25 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
26 ## All three arguments must be scalars.
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
27 ##
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
28 ## See also: logspace
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
29
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
30 ## Author: jwe
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
31
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
32 function retval = linspace (x1, x2, n)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
33
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
34 if (nargin == 2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
35 npoints = 100;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36 elseif (nargin == 3)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
37 if (length (n) == 1)
900
f8c8c2461f4d [project @ 1994-11-09 18:39:40 by jwe]
jwe
parents: 415
diff changeset
38 npoints = fix (n);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
39 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
40 error ("linspace: arguments must be scalars");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
41 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
42 else
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 900
diff changeset
43 usage ("linspace (x1, x2 [, n])");
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
44 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
45
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
46 if (npoints < 2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
47 error ("linspace: npoints must be greater than 2");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
48 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49
2697
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
50 ## In some cases x1 + delta * (npoints - 1) will not be equal to x2,
6243c37ae2c5 [project @ 1997-02-18 17:51:21 by jwe]
jwe
parents: 1098
diff changeset
51 ## so we cheat and force the last value to be x2.
1098
c0f319a1e51d [project @ 1995-02-13 16:46:08 by jwe]
jwe
parents: 1014
diff changeset
52
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
53 if (length (x1) == 1 && length (x2) == 1)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
54 delta = (x2 - x1) / (npoints - 1);
1098
c0f319a1e51d [project @ 1995-02-13 16:46:08 by jwe]
jwe
parents: 1014
diff changeset
55 retval = [x1+(0:npoints-2)*delta, x2];
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
56 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
57 error ("linspace: arguments must be scalars");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
58 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
59
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
60 endfunction