ub on History. Consider the function f(z) = r2-Z. and observe that when r-V2. f(
ID: 3877028 • Letter: U
Question
ub on History. Consider the function f(z) = r2-Z. and observe that when r-V2. f(r)-0. Also notice that although square roots are difficult to compute, it is easy to evaluate the value of f(a) for any provided value. Newton's method starts with an initial guess for r (for example, z 1) and then iterati the value of z to improve the approximation. At each step, the new value of z is computed to be f(x) where f'(a) is the derivative of f(x). For the specifie case of the function f(n) - Z, the formula would be 2z The table below shows an example of Newton's method with 5 steps using the function fr)-6 (that is, where the value of Z is set to 6). The initial guess for is 1.0. Notice how, at each step, the value of 12 gets closer to the goal value of 6. StepTold-valueTold-value-(squared) New z value New r value (squared) lue (squared) New z value New r value (squared) 10000000000 12.2500000000 6.79719387762.4512563601 6.0233742810 6.0000226763 .3000000000 2.6071428571 10000000000 3.5000000000 2.6071428571 2.4542363601 2.4494943716 12.2%)(XXXXXX) 6.7971938776 6.0233742810 6.0000226763 2.4491943716 2.44948974286.0000000000 1.1 Your task Write a syntactically and semantically correct C program which uses the formulation of Newton's method described above. Your code should be stored in a file called nevton.c". The number of steps and the goal value (Z) should be easy to adjust in your code. This can be achieved by having variables called num.ateps and Z at the top of your program. During your demo. you will be expected to show the evaluator how to change both values. You should use a loop to perform the iterative process (instead of simply copying and pasting code). since otherwise it will not be possible to use a very large number of ste Your program should produce the tollowing output . Before the computation starts. print the number of steps and the value of Z At each step of the iteration, print the step nunber (with the first step numbered I) and old value of to 10 decinal places l the . After the end of the last step, print the final value of s to 10 decimal placesExplanation / Answer
Hello There,
PFB code for the requested functionality along with the output of test run
Code:
--------------------------
#include <stdio.h>
void newtonMethod(int z, int num_steps);
int main(){
int z = 6;
int num_steps = 5;
printf("Value of z = %d ", z);
printf("number of steps = %d ", num_steps);
newtonMethod(z, num_steps);
return 0;
}
void newtonMethod(int z, int num_steps){
double x = 1;
printf("Step old value of x ");
for (int i = 0; i < num_steps; ++i){
printf("%d %.10f ", i+1, x);
x -= (x*x - z)/(2*x);
}
printf("Final Value of x for z = %d after %d steps :%.10f ", z,num_steps, x);
}
----------------
Output of test run:
-------------------------
$ ./a.out
Value of z = 6
number of steps = 5
Step old value of x
1 1.0000000000
2 3.5000000000
3 2.6071428571
4 2.4542563601
5 2.4494943716
Final Value of x for z = 6 after 5 steps :2.4494897428
$
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.