Recursion Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Recursion Help

  1. #1
    Join Date
    Jan 2010
    Posts
    4

    Recursion Help

    I cant get this function to recursively call itself what do i have in wrong i go through debugger and it just slides right over the recursive call

    double recursive (double left, double permaRight,double permaTol, double right, double tol)
    {
    double leftArea, rightArea, fullArea, areaAB, finalArea=0, recursiveAreaDifference=0, midpointer;
    leftArea = funcArea(F(left), F(midpoint(left,right)), midpoint(left,right),left);
    rightArea = funcArea(F(right), F(midpoint(left,right)), midpoint(left,right),right);
    fullArea = funcArea(F(left),F(right),(midpoint(left,right)*2),0);
    areaAB = (leftArea +rightArea);
    midpointer = midpoint(left,right);
    finalArea += areaAB;

    if(left == permaRight)//if the changing left bound = the user defined right limit
    {
    return finalArea; //progressive addition of the area
    }

    if((areaAB) <= ((fullArea + tol)||(fullArea -tol)))
    {
    permaTol -( fabs(areaAB - fullArea));
    recursiveAreaDifference += fabs((areaAB - fullArea));
    left = right;
    right = permaRight;
    return (recursive(left,permaRight,permaTol, right, tol));
    }

    else
    {
    return recursive(left,permaRight, permaTol, midpoint(left,right), tol/2);
    }

  2. #2
    Join Date
    Feb 2009
    Posts
    326

    Re: Recursion Help

    Thought it would be helpful if u did the following:

    couple of points:
    1) use code tags to place your code inside them [_code] /[_/code] without the underscore
    2) pls post the min possible code required, the following functions are not defined:

    F
    midpoint
    funcArea

    3) Pls provide sample valid values to call the function recursive (provide main() function to invoke the recursive function, so that it would be a complete program)

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: Recursion Help

    Quote Originally Posted by eugenesmonkey View Post
    if((areaAB) <= ((fullArea + tol)||(fullArea -tol)))
    Here you probably want to check whether areaAB is close to fullArea within a certain tolerance. It should look like this,

    if (areaAB >= (fullArea - tol) && areaAB <= (fullArea + tol))

    Note that the tolerance you're allowing is 2.0*tol. To be totally correct you probably should divide tol with 2.0 above.
    Last edited by nuzzle; January 30th, 2010 at 12:46 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center