Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Riemanns 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);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+How should it be delivered?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago