Search for question
Question

Queens College, CUNY Physics Department HOMEWORK ASSIGNMENT 4 Numerical Differentiation Part 1 - Differentiation Methods Create functions that outputs the result of the following differentiation methods: Two-Point Forward Difference Method: f' (x) ≈ (f(x + h) − f(x))/h Two-Point Backward Difference Method: f' (x) ≈ (f(x) − f(x − h))/h Three-Point Central Difference Method: ƒ' (x) ≈ (f(x + h) − f(x − h))/2h The functions should take input: function handle, point/array of where to compute the derivative, step size. Part 2 – Method of Choice Create function similar to that of Part 1 but includes an optional input that determines the differentiation method. You may use the same functions from Part 1 and make use of the MATLAB's switch control flow. Part 3 Error Analysis - Make a table of the error of the three-point centered-difference formula for f'(0), where f(x) = sin x - cos x, with h = 10-1,..., 10-12, (see table below). Draw a plot of the results. Does the minimum error correspond to the theoretical expectation? For illustration, the results of the Two-Point FDM for f(x) = exp(x), evaluated at x = 0 is shown in the following table and plotted in higher resolution (250 points) on a log-log plot: h 1.00E-01 1.00E-02 fFDM (x) Error 10º 1.05170918 f(x)=exp(x) 0.05170918 1.00501671 1.00E-03 0.00501671 1.00050017 0.00050017 1.00E-07 1.00E-08 1.00E-09 1.00000005 0.00000005 0.99999999 -0.00000001 1.00000008 0.00000008 Error 10-5 1.00E-13 1.00E-14 1.00E-15 : 0.99920072 0.99920072 -0.00079928 1.11022302 -0.00079928 10-10 0.11022302 10-15 10-10 10-5 10° h Page 1/2 Numerical Integration and Quadrature Part 1 Integration Methods Create functions that outputs the result of the following quadrature methods: • Left Side Method Right Side Method Trapezoid Rule Midpoint Method The functions should take input: function handle, integration boundaries, and the number of subintervals. As an example, the following is a sample function for the Left Side Method: Part 2 - Method of Choice As with the differentiation methods, create function similar to that of Part 1, but includes an optional input that determines the quadrature method. Part 3 Error Analysis - Make a table to illustrate the difference in the rate of convergence for the different methods with increasing number of subintervals. Do not use a linear function to illustrate this as these methods will produce exact results even with a single interval. Page 2/2