Write a function file that uses a newton Raphson algorithm to calculate the root
ID: 3669965 • Letter: W
Question
Write a function file that uses a newton Raphson algorithm to calculate the roots of function. Your input arguments should be the function, its derivative, and the range over which to search for the roots, and the increment size.
1. Write a script file that calls this function and tests it with the functions,
On the interval [-5, 5] and with two different increments (step sizes), 0.1 and 0.5
3. The program should perform a searching algorithm to identify regions that may contains roots and then select an initial guess based on that region.
a. The searching algorithm should test the sign of the function at both ends of the interval.
b. It should also test the sign of the derivative at both ends of the interval. If he derivative has opposite signs at the ends of the interval while the function has the same sign, the interval should be divided in half and retested (explain why this is)
4. In the newton Raphson loop, test if the derivative of the initial guess is zero and increment it slightly so as to avoid a singularity (explain this in your report).
5. The program should notify the user if it begins to diverge.
6. Verify your program with a problem related to your field of study.
I need code in that text format that can copied easily from here (thank you )
F(x) 1.2x4-1.5x3-6,0x2 8.2x-0.6Explanation / Answer
//Define function
double NewtonRaphson(double a[10], double start, int iterations, double deriv)
{
// Initialise array
for ( int m=0; m<10; m++){
a[m] = 0;
}
double root = start, function = 0, derivative=deriv;
// Newton-Raphson algorithm
for( int r=0; r < iterations; r++){
for( int p=1; p<10; p++){
function += a[p]*pow(root,p-1);
}
for ( int q=2; q<10; q++){
derivative += a[q]*pow(root,q-2)*(q-1);
}
root -= (function/derivative);
}
return root;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.