%%Matlab function for finding derivative using central
difference
clear all
close all
%Function for which derivative have to do
f=@(t) cos(3*pi*t);
%exact derivative of the function
df=@(t) (3*pi)*(-sin(3*pi*t));
%numerical derivative of the function
num_df=@(t,h) (cos(3*pi*(t+h))-cos(3*pi*(t-h)))./(2*h);
%all time value for which derivative have to find
tt=linspace(-1,1,1000);
%all discretization size
N=[10 40 70];
%loop for findind derivative for all N
for i=1:length(N)
h=2/N(i);
for j=1:length(tt)
val(i,j)=num_df(tt(j),h);
end
hold on
plot(tt,val(i,:))
%finding maximum error
err=max(df(tt)-squeeze(val(i,:)));
fprintf('\tMaximum error for N=%d is
%f.\n',N(i),err)
end
%plot for exact derivative
plot(tt,df(tt),'linewidth',2)
title('Exact and numerical derivative for various N')
xlabel('t')
ylabel('derivative of f(t)')
legend('For N=10','For N=40','For N=70','Exact value')
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%
Compute the derivative of f(t) cos(37t) on the interval 1,1) using a centered differences approximation with discretization size N 10,40 and 70. Plot the resulting approximations on the same graph as...
Compute the derivative of f(t) cos(37t) on the interval 1,1) using a centered differences approximation with discretization size N 10,40 and 70. Plot the resulting approximations on the same graph as the exact derivative. Find the maximum of the error for each of the three N values.
Problem 5. Consider least squares polynomial approximation to f(x) = cos (nx) on x E [-1,1] using the inner product 1. In finding coefficients you will need to compute the integral By symmetry, an 0 for odd n, so we need only consider even n. (a) Make a change of variables and use appropriate identities to transform the integral for a to cos (Bcos 8)cos (ne) de (b) The Bessel function of even order, (x), can be defined by the...