Question: PROBLEM #4 Using Mathlab Create a function file called trap_int.m that inputs a function f, a pair of endpoints, a; b, and a number n

 PROBLEM #4 Using Mathlab Create a function file called trap_int.m that

PROBLEM #4 Using Mathlab

Create a function file called trap_int.m that inputs a function f, a pair of endpoints, a; b, and a number n of subintervals, and outputs the approximation to the integral of f from a to b using the trapezoid rule on n points. Your function header should look like this function I = trap_int (f, a, b, n) Create a function file called Simp_int.m that inputs a function f, a pair of endpoints, a; b, and a number n of subintervals, and outputs the approximation to the integral of f from a to b using Simpsons rule on n points. Your function header should look like this function I = Simp_int (f, a, b, n) Consider the integral I = integral_-2^2 1/Squareroot 2 pi e^-x^2/2 dx Use the code you developed in Problems 2 and 3 to compute the integral for the number of points n = 10, 100; 1000; 10000 Compute the error in your computation for each n and for each method. Note that the exact answer to the given integral can be computed by using the error function erf in MATLAB, namely, I_exact = erf(Squareroot 2) - erf(-Squareroot 2)/2 Make a loglog plot of error verses the number of points for all methods on the same plot. Make sure to create a legend, showing which plot corresponds to which method. Comment on your results which method works better? Why

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!