January 29th, 2010 06:21 PM
#1
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);
}
January 29th, 2010 08:29 PM
#2
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)
January 29th, 2010 11:43 PM
#3
Re: Recursion Help
Originally Posted by
eugenesmonkey
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
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks