Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please attach a MATLAB code to be seen. Thank you Task 1: A central difference for Numeric differentiation Routine (8 pts) Use MATLAB to write
Please attach a MATLAB code to be seen. Thank you
Task 1: A central difference for Numeric differentiation Routine (8 pts) Use MATLAB to write a function called centraldiff.m that takes sample locations and function samplings at those locations as inputs and returns an approximation of the derivative at the sample points based on central finite difference method. The function should display nothing to the screen unless an error or warning occurs. The detailed specification is as follows The approximation of the derivative by central difference scheme is given as: 2 h D = centra!diff(x, fx) x : (N-element vector) numerical data for sample locations fx : (N-element vector) function data taken at locations defined in inputx D : Approximation for the first derivative of fx at a given data point. Valid call: Inputs: Output: D should have a length N Since the derivative of the first and the last point can't be found . using this method, assign zeros to the first and last elements of D Assumptions: Validation: The ith element of x corresponds to the ith element of fx and D 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 Hint: functions like isvector() and isnumeric) may come in handy during input validation Do not call any specialized MATLAB functions that perform differentiation. Write it from scratchStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started