Some corrections:
Code:
void LineSpace(float a, float b, int n, float* arrayOut)
{
int i = 0;
float interval = 0.0f, totalInt = 0.0f;
interval = (b - a)/(n - 1); //<-----formula was originally
//(b-a)/ (n-2); I experimented with (n-1) and
//it worked better.. not sure why?!?
totalInt = interval;
for (i = 0; i < n - 2; ++i)
{
arrayOut[i] = a + totalInt;
cout << " " << arrayOut[i] << " ";
totalInt += interval; // <----- doesn't work... this is
//supposed to add interval to itself each iteration
}
}
And what Salem meant is that if you want N intervals, you'll need N+1 points. Example: [0, 1) in 4 intervals:
Code:
Intervals [0,0.25), [0.25,0.5), [0.5, 0.75), [0.75, 1);
Points 0, 0.25, 0.5, 0.75, 1;