Hi, my prob is find the most accurate 1st derivative of f(x)=exp(cos(x)) at x=1, with h=0.5,0.25,..,2^(-16). I calculate the 1st der. using 1st order central diff formula & trying to improve the accuracy using Richardson extrap. got incorrect result

1 次查看(过去 30 天)
clear; clc; format shortG
f = @(x) exp(cos(x)); df = @(x) -exp(cos(x))*sin(x);
x = 1; Truef1 = df(x); A = [];
h = 1/2;
while (h >= 2^-16)
f1 = (f(x+h)-f(x-h))/(2*h);
A = [A; h f1];
h = h/2;
end
D(:,1) = A(:,2); E(:,1) = abs((Truef1-D(:,1))/Truef1);
for i = 1:16
for j = 2:i
D(i,j) = ((4^j)*D(i,j-1)-D(i-1,j-1))/(4^j-1);
E(i,j) = abs((Truef1-D(i,j))/Truef1);
end
end
disp(D); disp(E);
Order = (log(E(3,2))-log(E(2,2)))/(log(A(3,1))-log(A(2,1)))
loglog(A(:,1),E,'-');
  1 个评论
John D'Errico
John D'Errico 2016-3-9
编辑:John D'Errico 2016-3-9
Please learn to use the {} Code button when you post code. As you have posted it, this is unreadable.
Select the block of code, then click on the "{} Code" button. I'll fix it once for you.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by