Thread: Nodal points

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Question 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	
             }
    }
    Last edited by alyeska; 01-31-2008 at 10:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help it won't compile!!!!!
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-04-2009, 03:22 PM
  2. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  3. Replies: 1
    Last Post: 11-27-2007, 07:41 AM
  4. Yahtzee C++ programme help
    By kenneth_888 in forum C++ Programming
    Replies: 13
    Last Post: 09-05-2007, 02:14 PM
  5. CProg Fantasy Football version pi
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 155
    Last Post: 12-26-2006, 04:30 PM