First and Second Order Central Difference
Show older comments
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.
for
and make use of the 1st and 2nd order algorithms to numerically find the values of b.
Plot your results on two graphs over the range
, comparing the analytical and numerical values for each of the derivatives.
, 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 all
f=@(x) cosh(x)
x=linspace(-4,4,9)
n=length(x)
i=1:n
h=x(i)-x(i-1)
xCentral=x(2:end-1);
dFCentral=(F(i+1)-F(i))/(h);
Accepted Answer
More Answers (1)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
