Skip to Main Content Skip to Search
Product Documentation

plot::Integralnumerical approximation of an integral

plot::Integral(f, IntMethod = m) visualizes the approximation of the integral of the function  f using the numerical quadrature method  m. Riemann sums, the trapezoidal rule, and the Simpson rule are available.

plot::Integral(f, n, IntMethod = m) uses n  subintervals to approximate the integral.

→ Examples

Call:

plot::Integral(f, <n>, <IntMethod = m>, <a = amin .. amax>, Options)

Parameters:

f

the integrand: an object of type plot::Function2d.
f is equivalent to the attribute Function1.

n

the number of subintervals (a positive integer) or a list of real numbers representing nodes of the integration variable. 
n is equivalent to the attribute Nodes.

Options:

IntMethod = m

the quadrature method; see IntMethod

Related Domains:

plot::Function2d, plot::Hatch, plot::Text2d

Related Functions:

plot, plot::copy

Details:

Example 1

If a single plot::Function2d object is given without specifying an approximation method, plot::Integral just hatches the area between the function graph and the x-axis:

f := plot::Function2d(cos(x), x = -PI..PI):
plot(plot::Integral(f), f)

MuPAD graphics

Note that plot::Integral requires an object of type plot::Function2d, not just a function expression:

plot::Integral(sin(x))

Error: Expecting a 'plot::Function2d' object as first argument. [plot::Integral::new]

If an approximation method is specified, the numerical quadrature value computed by this method is displayed:

plot(plot::Integral(f, IntMethod = RiemannLower))

MuPAD graphics

The number of quadrature intervals can be set by passing a second argument n or by specifying Nodes = n:

plot(plot::Integral(f, 20, IntMethod = RiemannLower))

MuPAD graphics

To see the integrand in the plot, the function object must be passed together with the approximation object. The order determines which object is in front:

plot(plot::Integral(f, IntMethod = RiemannLower), f)

MuPAD graphics

delete f:

Example 2

The displayed information can be configured by the user:

f := plot::Function2d(x^2, x = -5..5, Color = RGB::DarkGrey):
plot(plot::Integral(f, IntMethod = RiemannLower,
       ShowInfo = [1, IntMethod = "Riemann lower sum",
                   Integral = "Exact value",
                   2, Error = "Difference"]), f)

MuPAD graphics

 

delete f:

 

Example 3

One may combine several approximation objects, e.g., lower and upper sum:

f := plot::Function2d(x^2, x = -5..5):
plot(plot::Integral(f, IntMethod = RiemannUpper,
                       Color = RGB::Blue),
     plot::Integral(f, IntMethod = RiemannLower,
                       Color = RGB::LightYellow),
     f)

MuPAD graphics

The automatically placed information texts overlap. To correct this, the option ShowInfo must be used. In the text of the upper sum, one additional empty line is inserted. Apart from this, both objects use the default value, therefore there is not need to specify ShowInfo in the second object:

plot(plot::Integral(f, IntMethod = RiemannUpper,
                       ShowInfo = [IntMethod, "", Integral]),
     plot::Integral(f, IntMethod = RiemannLower,
                       Color = RGB::LightYellow),
     f)

MuPAD graphics

The info text can be positioned explicitly:

plot(plot::Integral(f, IntMethod = RiemannUpper,
                       ShowInfo = [IntMethod, Integral,
                                   Position = [-5, -1]],
                       VerticalAlignment = Top),
     plot::Integral(f, IntMethod = RiemannLower, Color = RGB::Yellow,
                       ShowInfo = [IntMethod,
                                   Position = [0, -1]],
                       VerticalAlignment = Top),
     f)

MuPAD graphics

delete f:

Example 4

plot::Integral can be animated:

f := plot::Function2d(sin(a*x), x = 0..PI, a = 1..5):
plot(plot::Integral(f, 50, IntMethod = RiemannMiddle), f)

MuPAD graphicsimage

Increasing the number of nodes decreases the quadrature error:

f := plot::Function2d(sin(x), x = 0..PI):
plot(plot::Integral(f, N, N = 10..50, IntMethod = RiemannLower), f)

MuPAD graphicsimage

The function and the number of nodes can be animated simultaneously:

f := plot::Function2d(sin(a*x), x = 0..PI, a = 1..5):
plot(plot::Integral(f, N, N = 10..50, IntMethod = RiemannLower), f)

MuPAD graphicsimage

delete f:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS