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