Question: (c) (20 marks) Write a C program to compute the first derivative of f(x) = exp(x2) at x = 2 using the central-difference approximation scheme.
(c) (20 marks) Write a C program to compute the first derivative of f(x) = exp(x2) at x = 2 using the central-difference approximation scheme. In the program, you should also compute the exact value f using the analytic expression (What is it?) Calculate the differences E(h)- Seaa -um(h) for h 10-2,5x0-3,10-3,5 x 10-4, and 10-*, wherem)represents the numerical value obtained by using step size h. Plot In(E(h)) against In(h). Determine the slope of the line and verify that the error has the expected order of accuracy. [Optional: Improve your code to take arbitrary xo and h provided by the user: further improvement includes processing multiple h and writing the results into an output file, whose name is provided by the user.] (d) (20 marks) Write a C program. to compute the second derivative off(x)-explx2) at x = 2 using Eq. (6). Repeat the error analysis of part (c) for this case (c) (20 marks) Write a C program to compute the first derivative of f(x) = exp(x2) at x = 2 using the central-difference approximation scheme. In the program, you should also compute the exact value f using the analytic expression (What is it?) Calculate the differences E(h)- Seaa -um(h) for h 10-2,5x0-3,10-3,5 x 10-4, and 10-*, wherem)represents the numerical value obtained by using step size h. Plot In(E(h)) against In(h). Determine the slope of the line and verify that the error has the expected order of accuracy. [Optional: Improve your code to take arbitrary xo and h provided by the user: further improvement includes processing multiple h and writing the results into an output file, whose name is provided by the user.] (d) (20 marks) Write a C program. to compute the second derivative off(x)-explx2) at x = 2 using Eq. (6). Repeat the error analysis of part (c) for this case
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
