Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (50 points) You are given a function f(x) = sin(x) + cos(x) on the interval [-3,1] and you want to calculate the first

    

3. (50 points) You are given a function f(x) = sin(x) + cos(x) on the interval [-3,1] and you want to calculate the first derivative of this function at the points on this interval. Write a MATLAB program that: (a) Given the number N of subintervals, calculates the first derivative of the function, fi, at each point x, including the boundary points, with the first-order accuracy (this can be done as a self-written MATLAB function). You can use any formula of O(h) of your choice. (b) Given the number N of subintervals, calculates the first derivative of the function, f, at each point x, including the boundary points, with the second-order accuracy (this can be done as a self-written MATLAB function). You can use any formula of O(h) of your choice. (c) Calculates two measures of error defined as i. EL = maxi|ftrue (xi) fi| - ii. EL2 = N (firue(xi)-f) i=0 N+1 The first error is called the error in infinity norm (max; stands for the maximum value among all the points), and the second error is called the error in L2 norm. Here ftrue (xi) is the true value of derivative at the given point xi. You need: (a) Provide a write-up stating all the formulas you used for calculating the derivative for the first- order method, and for the-second order method, for the interior points, as well as for the left and right boundary points. (b) Run your program with the number of intervals N equal to 8, 16, 32, 64. (c) For N = 8 and N = 64, output the derivatives at the left and right boundary points. (d) Plot EL versus N, in log-log plot, for both the first-order method, and the second-order method, on the same plot. (e) Plot EL2 versus N, in log-log plot, for both first-order method, and the second-order method, on the same plot (but different from EL plot). (f) Estimate the order of accuracy for each derivative from the two plots (either calculate the slope from the graphs, or plot the theoretical order of convergence lines). (g) Discuss if you obtain the expected order of convergence, for both error measures.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

An Introduction to the Mathematics of financial Derivatives

Authors: Salih N. Neftci

2nd Edition

978-0125153928, 9780080478647, 125153929, 978-0123846822

More Books

Students also viewed these Programming questions

Question

=+a) Write the null and alternative hypotheses.

Answered: 1 week ago