Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone put this in a working C++ project for me. I put the code in main, bu

ID: 3649769 • Letter: C

Question

Can someone put this in a working C++ project for me.
I put the code in main, but it doens't work correctly



double modified_secant_root( double (*f)( double ), double xr,
double delta, double es )
{
double xrold;
int i;
for ( i=1; i<100; i++ ) {
double newxr, perturbation, ea;
double fxr = f(xr);
perturbation = delta * xr;
newxr = xr - ( (perturbation*fxr)/ ( f(xr+perturbation) - fxr ) );
ea = ( newxr - xr ) / newxr;
printf ( "%2d: xr=%f newxr=%f ea=%#2.6g%% ",
i, xr, newxr, ea*100 );
xr = newxr;
if ( (ea < 0 && (-ea) < es) || (ea > 0 && ea < es) )
return newxr;
}
return xr; }

Explanation / Answer

you would be producing error from constantly declaring variables inside your for loop. See if this work: double modified_secant_root( double (*f)( double ), double xr, double delta, double es ) { double xrold; int i; double newxr, perturbation, ea; double fxr; for ( i=1; i