Javatpoint Logo
Javatpoint Logo

MATLAB Trapezoidal Rule

Consider the function y=f(x) for the interval a≤x≤b, shown in figure:

MATLAB Trapezoidal Rule

To evaluate the definite integral, MATLAB Trapezoidal Ruledx, we divide the interval a≤x≤b into subintervals each of lengthMATLAB Trapezoidal Rule. Then, the number of points between x0=a,and xn=b is x1=a+∆x,x2=a+2∆x,…xn-1=a+(n-1)∆x. Therefore, the integral from a to b is the sum of the integrals from a to x1, from x1 to x2 and so on, and finally from xn-1 to b.

The total area is:

MATLAB Trapezoidal Rule 0 P1 x1that is equal toMATLAB Trapezoidal Rule plus the area of the trapezoid x1 P1 P2 x2 that is equal to MATLAB Trapezoidal Rule, and so on. Then, the trapezoidal approximation becomes

MATLAB Trapezoidal Rule

Example

Using the trapezoidal rule with n=4, estimate the cost of the definite integral

MATLAB Trapezoidal Rule

Compare with the exact value and evaluate the percent error.

Solution:

The exact value of this integral is

MATLAB Trapezoidal Rule

For the trapezoidal rule approximation, we have

MATLAB Trapezoidal Rule

and by substitution into an equation

MATLAB Trapezoidal Rule

From equation 3 and equation 4, we find that the percent error is

MATLAB Trapezoidal Rule
Next TopicMATLAB Trapz




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA