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
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
John D'Errico
am 9 Mär. 2016
Bearbeitet: John D'Errico
am 9 Mär. 2016
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!