Section4.1Numerical Differentiation
From Taylor's Theorem we know that \begin{equation*} f(x) = f(a) + \frac{f'(a)}{1!} (x-a)^1 + \frac{f''(a)}{2!}(x-a)^2 + \frac{f^{(3)}(a)}{3!}(x-a)^3 + \frac{f^{(4)}(a)}{4!}(x-a)^4 + \cdots \end{equation*}
What do we get if we replace \(x\) with \((x+h)\) and \(a\) with \(x\)?
Solve the result form the previous problem for \(f'(x)\) to create an approximation for \(f'(x)\) using \(f(x+h)\), \(f(x)\), and some higher order terms. How can we use Taylor's Theorem to quantify the error of this approximation?
Write Excel and MATLAB code that takes a data set from an unknown function and returns a first-order accurate numerical approximation of the derivative of the function. Test your code on data gerenated from the function \begin{equation*} f(x) = \sin(x) - x\sin(x) \text{ on } x \in (0,15) \end{equation*} with various step sizes. Provide a plot of the error between the analytic derivative and the numerical derivative using a semi-logy scale. Note: You will lose some information along the way (why?).
Consider again the Taylor series for an infinitely differentiable function \(f(x)\): \begin{equation*} f(x) = f(a) + \frac{f'(a)}{1!} (x-a)^1 + \frac{f''(a)}{2!}(x-a)^2 + \frac{f^{(3)}(a)}{3!}(x-a)^3 + \frac{f^{(4)}(a)}{4!}(x-a)^4 + \cdots \end{equation*}
This time, replace \(x\) with \((x-h)\) and \(a\) with \(x\) and simplify. Subtract this form of the Taylor Series from the form found in Problem 4.1.1 to get a second-order accurate approximation for the first derivative of \(f\).
Writet MATLAB code that takes a function and a domain \([x_{min} , x_{max}]\) and returns a numerical approximation to the derivative on the interval \((x_{min} , x_{max})\). Your function should accept an anonymous function handle, the bounds on the domain, and the number of interior points used for approximation within the domain.
Write Excel and MATLAB code that takes a data set from an unknown function and returns a second-order accurate numerical approximation for the first derivative. Test your code on data generated by the same function as in Problem 4.1.3 and provide error plots that compare your first- and second-order accurate differentiation code.
Add the Taylor Series representations from Problems 4.1.1 and 4.1.4 to arrive at an approximation of the second derivative. What is the order of the error? Test your code on the same function from Problem 4.1.3. Create an error plot showing the accuracy of the method.
Go to the http://apps.who.int/gho/data/?theme=home (The World Health Organization Data Repository) and find a data set where it would make physical sense to take a first or a second derivative (and that the derivative would tell you something meaningful about the data). Use your MATLAB code to take the derivative and provide plots as well as context and meaning associated with the plot. You will need to download the data as a CSV or Excel file and import the proper columns into Excel (Google “xlsread” to learn how MATLAB imports Excel data). Your data set will obviously involve some noise, but one thought might be to find a data set that shows a trend in time.
(Coding Challenge) 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Write code to find the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?