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...
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
  • 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. 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...

  • Problem 5. Consider least squares polynomial approximation to f(x) = cos (nx) on x E [-1,1] using...

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

  • please show me a Matlab script that will compute the total errors of the approximation due...

    please show me a Matlab script that will compute the total errors of the approximation due to the given function, also include the panel plot as well, thank you. 1) This problem studies the errors due to the approximation of the first derivative of a given function f(x) using the forward and centered difference methods. For this problem, we consider f(x)=sin(x). a) First, we will investigate the effect of the step size h on the first derivative approximation. Set h=10',...

  • Please help me answer this question using matlab Consider the function f(x) x3 2x4 on the...

    Please help me answer this question using matlab Consider the function f(x) x3 2x4 on the interval [-2, 2] with h 0.25. Use the forward, backward, and centered finite difference approximations for the first and second derivatives so as to graphically illustrate which approximation is most accurate. Graph all three first-derivative finite difference approximations along with the theoretical, and do the same for the second derivative as well

  • 3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 point...

    3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 points of this function: 10.5403 2 -0.4161 6 0.9602 (a) (2 points) Calculate the quadratic Lagrange interpolating polynomial as the sum of the Lo(x), L1(x), L2(x) polynomials we defined in class. The final answer should be in the form P)a2 bx c, but with a, b, c known. DELIVERABLES: All your work in constructing the polynomial. This is to be done by hand...

  • please explain how to do step 5 in matlab commands. med at x=c. 2 The first derivative Ne Scr We investigate the function f(x) 4 12x3+9x2. >> x-linspace (-3,3) >> y-41x.^4-12*x.^3 &gt...

    please explain how to do step 5 in matlab commands. med at x=c. 2 The first derivative Ne Scr We investigate the function f(x) 4 12x3+9x2. >> x-linspace (-3,3) >> y-41x.^4-12*x.^3 >> plot (x,y), grid 9*x."2; + A plot over the interval I-3,3] reveals an apparent "flat section"' with no visible relati extrema. To produce a plot that reveals the true structure of the graph, we replot over the interval [-1,2]: >> x=linspace (-1,2); >> y= 4 * x. ^4-12*x.^3...

  • 5. (12.5%) The ideal D/A converter described by equation (6.25), equation (6.20), and equation (6...

    Please offer the Matlab code.Answer the question b.c.f.g. 5. (12.5%) The ideal D/A converter described by equation (6.25), equation (6.20), and equation (6.24) cannot be constructed because they require an infinite number of past and future samples of c(t) for the interpolation. However they can be approximated by using only a finite number of terms. Here we consider 2 methods Method I is to use only (N 1) terms of the sum in equation (6.25) as: sin IT(t nT)/T] T(t...

  • Please answer "b" only. %Example code function plotFS(m); %m = user provided number of terms desired in the Fou...

    Please answer "b" only. %Example code function plotFS(m); %m = user provided number of terms desired in the Fourier series; %this code computes the Fourier series of the function %f(x)=0, for -pi<= x <0, % =cos(x) for 0<= x <pi %generate the interval from -pi to pi with step size h; h = pi/100; xx1=[-pi:h:0]; xx2=[0:h:pi]; xx = [xx1, xx2]; %generate the given function f so that it can be graphed ff = [zeros(size(xx1)), cos(xx2)]; %compute the first partial sum...

  • I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT...

    I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT WE HAVE A SUB AND HE DIDN'T TEACH IT! ITS EULER AND IMPROVED EULER IN MATLAB! HERE IS THE LINK FOR THE IMAGE FILE THAT SHOWS THE FULL INSTRUCTIONS FOR THE CODE. https://imgur.com/a/gjmypLs Also, here is my code so far that I borrowed form an old assignment but the data is all wrong and the application of the code is slightly different so either...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

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