Question: MATLAB Code for Numerical differentiation function. Here's my code so far for the function: function [df] = numericalDerivative(x,f,type); n = length(x); h = x(2)- x(1);
MATLAB Code for Numerical differentiation function.
Here's my code so far for the function:
function [df] = numericalDerivative(x,f,type);
n = length(x); h = x(2)- x(1);
if strcmp(type, 'FL') % Forward Difference for i = 1:n-1 df(i) = (f(i+1) - f(i))/h; % Forward Difference equation end df(n) = (f(n) - f(n-1))/h; %backward difference at last point elseif strcmp(type,'BL') % Backward Difference for i = 2:n df(i) = (f(i) - f(i-1))/h; % Backward Difference equation end df(1) = (f(2) - f(1))/h; % Forward difference at first point
elseif strcmp(type,'CL') % Centered difference
for i = 2:n-1 df(i) = (f(i+1) - f(i-1))/2*h; % Centered difference equation .... elseif strcmp(type,'FM') % Higher Accuracy Forward Difference
.... elseif strcmp(type,'BM') % Higher Accuracy Backward DIfference
.....
elseif strcmp(type,'CM') % Higher accuracy Centered difference ..... I need code to fill in the blanks for CL, FM, BM and CM. It should be very similar to the rest of the code. Thanks, Like will be given!
Given this discrete approximation to f(sin(r you now seek to compute the derivative of f(r) at each of the n sample points. To accomplish this you will write one function and one main program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
