In: Advanced Math
solve using MATLAB.
Title: Numerical differentiations.
Use Richardson extrapolation to estimate the first derivative of y = cos x at x = π/4 using step sizes of h1 = π/3 and h2 = π/6. Employ centered differences of O(h2) for the initial estimates.
solve using MATLAB.
%%Matlab code for Richardson Extrapolation
clear all
close all
%function for which differentiation have to do
f=@(x) cos(x) ;
x=pi/4;
h1=pi/3; h2=pi/6;
%differetiation using central difference
df1=(f(x+h1)-f(x-h1))/(2*h1);
df2=(f(x+h2)-f(x-h2))/(2*h2);
fprintf('\tExact differential at x=pi/4 is %f\n',-sin(x));
fprintf('\tCentral difference for h1=%f is %f\n',h1,df1)
fprintf('\tCentral difference for h2=%f is %f\n',h2,df2)
dff=df2+((df2-df1)/3);
fprintf('\tRichardson extrapolation at x=%f is %f\n',pi/4,dff)
%%%%%%%%%%%% End of Code %%%%%%%%%%%