Question

Compute the derivative of f(t) cos(37t) on the interval 1,1) using a centered differences approximation with discretization s

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab function for finding derivative using central difference clear all close all Function for which derivative have to doExact and numerical derivative for various N 10 -For N. 10 -For N:40 -For N:70 Exact value -4 -6 10 1 08 6.4 -02 06 08 Publis

%%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 %%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT