Question: Fordiff: 9. Starting with your fordiff.m code, write code called testdiff.m where instead of choosing h, use a loop to output the error for h

Fordiff:

9. Starting with your fordiff.m code, write code called testdiff.m where instead of choosing h, use a loop to output the error for h the true derivative at your input x. I recommend a for loop with i=1:8 and use this to set the value of h. Do the output errors agree with the theory ten reduces the error by a factor of ten? Add your answer as comment to the code. 10-1, 10-2, -.. , 108. You will have to calculate that reducing h by a factor of Add a second loop to your code that replaces the first order forward difference approximation with the second order forward difference approximation. Do the output errors agree with the theory that reducing h by a factor of ten reduces the error by a factor of one hundred? Add your answer as comment to the code. We shall revisit this odd behavior later. Make sure you follow the guidelines with regard to commenting, preamble, and nicely for- matted output. Submit your Matlab file. input ('Enter a value for x '); input ('Enter a value for h '); h % Derivative: (1/h)* (sqrt (x) +h-sqrt (x)); % Output stuff: fprintf('the value of F is %15.10f ' ,F); 5. Write a Matlab program called fordiff1.m that asks the user to input an x value and a small h value. The program should calculate the square root of x, approximate the derivative of the function Va and print them both to the screen. You should be descriptive in your output. For the approximate derivative, the definition of derivative suggests f'(x) ~ }(f(x+h) f(x)) for given r and small h, with f(x)= Vx
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
