フィルターのクリア

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 日間)
Umesh Prajapati
Umesh Prajapati 2016 年 3 月 9 日
編集済み: John D'Errico 2016 年 3 月 9 日
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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by