Question: 1. Write a Matlab code to integrate a function that is approximated using a uniformly spaced array of points. The function should have the form

 1. Write a Matlab code to integrate a function that is

1. Write a Matlab code to integrate a function that is approximated using a uniformly spaced array of points. The function should have the form function (integral] integrate(dx, values) where dx is the mesh spacing and values is the list of values. Use Simpson's 1/3 rule for the integration. 2. Test the routine by integrating exp(2x) sin?(27x) on the domain x [0, 1]. Use the command x = linspace(0,1,n) to generate the locations and then generate the function values at those location like you did in the previous homework. For this assignment, you will do this 4 times with N = V = 3,5,9,17,33 so you can see how the approximation changes as the number of points increases (h decreasing by a factor of 2). Calculate the exact value of the integral (you can use symbolic variables in Matlab to do the exact integral) and use it to calculate the absolute error in integral as a function of N. Make a loglog plot of the error versus N Here is how to construct the loop and store the array values Nlist = 2.^(1:5] +1; for i=1:length(Nlist) N = Nlist(i) dx = values = Errorlist(i) = dxlist(i) = dx; end loglog(dxlist, Errorlist) 3. Calculate the slope of log(Error) versus log(dx) using the last two data points from the above. Does the convergence rate agree with what you expect? 1. Write a Matlab code to integrate a function that is approximated using a uniformly spaced array of points. The function should have the form function (integral] integrate(dx, values) where dx is the mesh spacing and values is the list of values. Use Simpson's 1/3 rule for the integration. 2. Test the routine by integrating exp(2x) sin?(27x) on the domain x [0, 1]. Use the command x = linspace(0,1,n) to generate the locations and then generate the function values at those location like you did in the previous homework. For this assignment, you will do this 4 times with N = V = 3,5,9,17,33 so you can see how the approximation changes as the number of points increases (h decreasing by a factor of 2). Calculate the exact value of the integral (you can use symbolic variables in Matlab to do the exact integral) and use it to calculate the absolute error in integral as a function of N. Make a loglog plot of the error versus N Here is how to construct the loop and store the array values Nlist = 2.^(1:5] +1; for i=1:length(Nlist) N = Nlist(i) dx = values = Errorlist(i) = dxlist(i) = dx; end loglog(dxlist, Errorlist) 3. Calculate the slope of log(Error) versus log(dx) using the last two data points from the above. Does the convergence rate agree with what you expect

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!