Higher order derivatives

Question 1: Higher order derivatives Write a function numdiff5 that approximates the fifth derivative of an unknown function f . The function numdiff5 has to be written in the file numdiff5.m, and its first line looks like this: function y=numdiff5(f,x) For any x it should return (an approximation of) the fifth derivative y = f (v)(x) of the unknown function f . You can assume that the function f can be evaluated everywhere.
I have created this script:
function y=numdiff5(f,x)
h=0.1;
dy=(f(x+h)-f(x-h))/(2*h);
dy5=(-f(x-3*h)+4*f(x-2*h)-5*f(x-h)+5*f(x+h)-4*f(x+2*h)+f(x+3*h))/(2*h^5);
for a=h/2;
dya=(f(x+a)-f(x-a))/(2*a);
dyb=((dya-dy)/3);
end
y=dya+dyb+((h^4)/160)*dy5;
end
because I was told that I needed to use Richardson extrapolation in order to improve accuracy but how have been told I have used it wrong. So how would I correct the script for accuracy >=10^-9?

回答(2 个)

I am still trying to digest the Richardson extrapolation, but I can offer a couple of suggestions.
1) your definition of h is fixed. In order to approximate the derivative, h has to be "small" compared to x. Perhaps h=x/100? Also, maybe redefining:
dy = (f(x+h)-f(x))/h
2) is dy5 derived from the taylor expansion? If so, you might want to check that.
Also, doesn't
for a=h/2
give you an error?

2 个评论

1) i have been told making h smaller will give me a less accurate answer
2) dy5 was found on the internet but was checked and confirmed to be right by my lecturer
and no for a=h/2 doesn't give me an error
a = h/2 doesn't give an error because it sets a equal to h/2 and goes through the loop once. That makes the loop pointless.

请先登录,再进行评论。

There is a lot of stuff that doesn't belong there. This line
dy=(f(x+h)-f(x-h))/(2*h);
is a finite difference formula for the first derivative, which you're not calculating. This line
y=dya+dyb+((h^4)/160)*dy5;
seems to be incorporating an estimate for the error in the expression. And, as I pointed out in a comment, the loop is pointless.
The idea behind Richardson extrapolation is to make two estimates of the quantity you want (the fifth derivative) and combine them. You could define an anonymous function
dy5= @(h) (-f(x-3*h)+4*f(x-2*h)-5*f(x-h)+5*f(x+h)-4*f(x+2*h)+f(x+3*h))/(2*h^5);
and then the expression you need is
y = dy5(h/2) + (dy5(h/2)-dy5(h))/3;
This is the MATLAB part. I'll leave it to you to decide whether this is accurate enough. That's the math part.

2 个评论

I have read all the comments and attempted to take them on board but I am confused as to what im meant to be showing and how to write it in a script for what the question is asking
I understand we know dy5 but where do we go from there and how do we show this?
Moya, I think I have said too much already. We try not to do your homework for you because, in the long run, it is better if you solve the problem yourself. Clearly, you do not understand Richardson extrapolation. I think you should go back, review what it is and look at an example of its use, and then you'll see why I have practically written down the solution for you.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Spline Postprocessing 的更多信息

产品

提问:

2011-5-16

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by