Use MATLAB to solve problem and show work. 2 2. (3 points) Consider the followin
ID: 3602931 • Letter: U
Question
Use MATLAB to solve problem and show work.
2 2. (3 points) Consider the following integral:esin(a) dr 0 (a) Ok. This integral is hard to solve by hand. MATLAB has a built-in function that uses adaptive quadrature to get the result. The syntax is below exact integral (f, a,b); % f function, [a,b] = domain of integration This is an approximation, but it's a very good one. We'll consider it to be the exact answer. What is this exact answer? (b) Use this and your code from HW10 to complete the table below. We will just look at the Trapezoid rule for this particular integral trap error trap error / h2 1.6717 1.6938 × 10-1 16 32 (c) Look at column 2. Does Trapezoid rule converge to the right answer? (d) Look at column 3. Does Trapezoid rule converge at the right rate? If not, is it converging faster or slower than expected (e) Try it again, but this time integrate over 10, 1] instead of [0.2 Does Trapezoid rule converge to the right answer? Does Trapezoid rule converge at the right rate? (f) The trapezoid rule works like magic for some integrals. It is called "spectral accu racy" or "superalgebraic convergence." Given what you saw here, what is special about f(z) and a, b that gives a spectrally accurate Trapezoid rule?Explanation / Answer
function integral = cmptrap(a,b,n,f) h = (b-a)/n; x = [a+h:h:b-h]; integral = h/2*(2*sum(feval(f,x))+feval(f,a)+feval(f,b)); Run with cmptrap(1,2,4,’f’) where ’f’ is the name of the function definition file function y = f(t) y = t.*log(t); % pay attention to the dot The result is 0.6399004. 2a. Matlab code for the Composite Simpson’s rule function integral = cmpsimp(a,b,n,f) h = (b-a)/n; xi0 = feval(’f’,a)+feval(’f’,b); xi1 = 0; xi2 = 0; for i = 1:n-1 x = a+i*h; if mod(i,2) == 0 xi2 = xi2+feval(’f’,x); else xi1 = xi1+feval(’f’,x); end end xi = h*(xi0+2*xi2+4*xi1)/3; xi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.