The 1st order central difference (OCD) algorithm approximates the first derivative according to ,
and the 2nd order OCD algorithm approximates the second derivative according to .
In both of these formulae is the distance between neighbouring x values on the discretized domain.
a.
Write a script which takes the values of the function for and make use of the 1st and 2nd order algorithms to numerically find the values of and . You may use the analytical value of to find initial condtions if required.
b.
Plot your results on two graphs over the range , comparing the analytical and numerical values for each of the derivatives.
c.
Compare each numerical algorithms results by finding the largest value of the relative error between the analytical and numerical results.
Can someone please help with this question? I'm stuck on where to begin really. Thanks! This is what I have so far, but comes up with errors.
clear allf=@(x) cosh(x)x=linspace(-4,4,9)n=length(x)i=1:nh=x(i)-x(i-1)xCentral=x(2:end-1);dFCentral=(F(i+1)-F(i))/(h);
Best Answer