]> gitweb.michael.orlitzky.com - octave.git/blob - partition.m
ec1bc8bec617ab1e450a6f502157ce6e91cdc85e
[octave.git] / partition.m
1 function [p,delta] = partition(integerN, a, b)
2 % Partition the interval [a,b] into integerN subintervals. We do not
3 % require that a<b.
4 %
5 % INPUT:
6 %
7 % * ``integerN`` - The number of subintervals.
8 %
9 % * ``a`` - The "left" endpoint of the interval to partition.
10 %
11 % * ``b`` - The "right" endpoint of the interval to partition.
12 %
13 % OUTPUT:
14 %
15 % * ``p`` - The resulting partition, as a column vector of length
16 % integerN+1.
17 %
18 % * ``delta`` - The distance between x_i and x_{i+1} in the
19 % partition.
20 %
21 %
22
23 % We don't use abs() here because `b` might be less than `a`. In that
24 % case, we want delta negative so that when we add it to `a`, we move
25 % towards `b`.
26 delta = (b - a)/integerN;
27
28 p = [a : delta : b]';
29 end