Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise you will approximate the value of the definite integral of a po

ID: 3856029 • Letter: I

Question

In this exercise you will approximate the value of the definite integral of a polynomial using both Riemann sums and a MATLAB built-in function int.

The code accepts as inputs: a polynomial P, a vector n, and two scalars a, b. The program will use Riemann sums to approximate the definite integral on the interval [a,b] of a given polynomial P. Riemann sum calculations should be performed using partitions of [a,b] by subintervals of equal length h defined as

h = (b – a)/n(j),

where n(j) is a jth entry on n, j=1:N, and N= length(n). Each entry of vector n, n(j), is equal to the number of subintervals of the corresponding partition of

Your function has to return a table T whose first column is the vector n. Columns 2 – 4 are the column vectors c’, d’, f’ of the Riemann’s sums approximations of the integral of P on the interval [a, b], with the numbers of subintervals of partition defined by the entries of n, and the value of the function to be chosen at the left endpoints (gives vector c), at the middle points (gives vector d), and at the right endpoints (gives vector f) of each subinterval of the partition.

function [T, I] = reimsum(P,a,b,n)

that calculates vectors c, d, f as described above and forms a matrix A = [n’, c’, d’, f ’].

The following command converts the 4-by-N array A into a 4-by-N table T with the names of the variables as indicated below:

T=array2table(A,...

    'VariableNames',{'n','Left','Middle','Right'})

You should use format long in you code.

You will output the table and, besides that, the value of the integral I, calculated by means of the MATLAB function int, specifically, I= double(int(P, a, b)). (double(s) converts the symbolic value s to double precision.)

The program could use nested for loops, the command sym2poly, and a MATLAB function polyval. Use closetozeroroundoff function (that you created in Exercise 3) on the variable d in your code, that is, to output d, write d= closetozeroroundoff (d);

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 Result: 0.6363098

Approximation: 2 ¡ 1 6 ¢ ¡ 7 6 ln 7 6 + 9 6 ln 9 6 + 11 6 ln 11 6 ¢ = 0.633096. 7. f(x) = e 2x sin 3x f 00(x) = 5 e 2x sin (3x) + 12 e 2x cos (3x) f (4)(x) = 119 e 2x sin (3x) 120 e 2x cos (3x) 1 For (0, 2) we look for an upper bound for ¯ ¯f 00() ¯ ¯ = ¯ ¯ ¯ e 2 (5 sin 3 + 12 cos 3) ¯ ¯ ¯ e 4 (5 + 12). Or for a better upper bound ¯ ¯f 00() ¯ ¯ = ¯ ¯ ¯ e 2 (5 sin 3 + 12 cos 3) ¯ ¯ ¯ e 4 p 5 2 + 122 = 13e 4 . We use the latter one(it’s OK if you use the first one; then you will get a larger n/smaller h). Similarly ¯ ¯ ¯f (4)() ¯ ¯ ¯ = ¯ ¯119 e 2x sin (3x) 120 e 2x cos (3 ) ¯ ¯ e 4 p 1192 + 1202 120 2e 4 . Thus by the error for the Composite Trapezoidal rule ¯ ¯ ¯ ¯ b a 12 h 2 f 00() ¯ ¯ ¯ ¯ 2 12 h 2 13e 4 < 104 = h < 9.1942 × 104 = n > 2175.3 (choose 2176).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote