Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need the correct Matlab code for this question ASAP!!! Thank you 3. (50 points) You are given a function f(x) = sin(x) on the interval
Need the correct Matlab code for this question ASAP!!! Thank you
3. (50 points) You are given a function f(x) = sin(x) on the interval (-2, 2] 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 Xi, 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, fi, at each point Xi, 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(ha) of your choice. (c) Calculates two measures of error defined as i. Els = mari|ftrue (xi) - fil ii. EL2 = i=o (ftrue(xi) f!) 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 El, 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 measuresStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started