Suppose you need to generate n + 1 equally spaced points on the interval [a, b], with spacing h = (b - a)/n.
(a) In floating-point arithmetic, which if the following methods,
x_0 = a, x_k = x_{k-1} + h, k = 1, 2, ..., n
or
x_k = a + kh, k = 0, 1, ..., n,
is better, and why?
(b) Write a program in MATLAB implementing both methods and find an example with particular values of a, b, and n, that illustrates the difference between them.
(c) Will the following pseudo-code
h = (b-a)/n; i = 0; x[0] = a;
while (x[i] < b) do
i = i+1; x[i] = x[i-1] + h
od
always produce the same number of equally spaced points as
h = (b-a)/n;
for i from 0 to n do
x[i] = a+i*h
od