1. ## Nodal points

Hi everyone,
I am working on a code that generates n evenly spaced nodal points from a to b. It runs but I can't get to add interval to itself every iteration, and I am not sure if I got the formula right.
Any ideas? Thanks, I appreciate it.

Sample output should be:
Code:
```a = 3
b = 5
n = 5
3  3.5  4  4.5  5```
Code is:
Code:
```#include <iostream>
using namespace std;

void LineSpace(float a, float b, int n, float arrayOut[]);

int main()
{
float a = 0.0f, b = 0.0f;
int n = 0;
cout << "Enter an interval [a,b] and number of nodal points n. " << endl;
cout << "Input a = ";
cin >> a;
cout << "Input b = ";
cin >> b;
cout << "Input n = ";
cin >> n;
float* arrayOut = new float[n];
cout << a;
LineSpace(a, b, n, arrayOut);
cout <<  " " << b << endl;
delete [] arrayOut;
arrayOut = 0;
}
void LineSpace(float a, float b, int n, float* arrayOut)
{
int i = 0;
float interval = 0.0f;
for (i = 0; i < n - 2; ++i)
{
interval = (b - a)/(n - 1); //<-----formula was originally
//(b-a)/ (n-2); I experimented with (n-1) and
//it worked better.. not sure why?!?
arrayOut[i] = a + interval;
cout << " " << arrayOut[i] << " ";
interval += interval; // <----- doesn't work... this is
//supposed to add interval to itself each iteration
}
}```

2. Think of a fence.
You need N panels, and N+1 posts.

- calculate interval just once outside the loop.
- use something like total += interval inside the loop.

3. Hi Salem..
I made the revisions in the code but nothing changed in the output. Here's the revised function.

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?!?
for (i = 0; i < n - 2; ++i)
{
arrayOut[i] = a + interval;
cout << " " << arrayOut[i] << " ";
totalInt += interval; // <----- doesn't work... this is
//supposed to add interval to itself each iteration
}
}```
I am also not sure what you meant here. Can you please elaborate? I appreciate your help and by that I meant you're not just giving me the answers but helping me figure it out myself.

Think of a fence.
You need N panels, and N+1 posts.

4. 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;```

5. Thanks nepper.. it's much clearer now.. and the program's completely running.