Question: Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function samplings at those locations as inputs and returns an

Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function samplings at those locations as inputs and returns an approximation of the derivative at the sample points based on forward finite difference method with order of accuracy O(h^3). The function should display nothing to the screen unless an error or warning occurs. The detailed specification is as follows: The approximation of derivative by forward difference method (for O(h^3) is given as: f' (x_1) = -f(x_i + 2) + 6f(x_i + 1) - 3f(x_i) - 2f(x_i - 1)/6h Valid call: I = forwarddiff(x, fx) Inputs: x: (N-element vector) numerical data for sample locations. fx: (N-element vector) function data taken at locations defined in input x. Output: I: Approximation for the first derivative of fx at data points 2 to N-2. Assumptions: The ith element of x corresponds to the ith element of fx. Validation: Your code should throw an error if any of the following are true: x and fx are not the same length either of the inputs are not vectors (e.g., a matrix) either of the inputs contains something other than numerical data
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
