This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Numerical approximation of an integral

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


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


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.

The attribute IntMethod determines the numerical method. Riemann sums, the trapezoidal rule, or the Simpson rule are available. See the help page of IntMethod for further details. Cf. Example 1.

plot::Integral does not plot the function graph of the integrand. If the integrand is to be plotted, too, f has to be passed to the plot command together with the approximation object of type plot::Integral.

If no quadrature method is specified by IntMethod = m, plot::Integral just hatches the area between the function f and the x-axis.

Several plot::Integral objects can be plotted together to illustrate the difference between various quadrature methods. The order of the objects in the plot command determines the object in front.

The plot contains a text object providing information about the quadrature method, the value of the approximation, the exact value of the integral, the quadrature error, and the number of nodes. See the help page of the attribute ShowInfo for further details.


AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
Colorthe main colorRGB::PaleBlue
Filledfilled or transparent areas and surfacesTRUE
FillColorcolor of areas and surfacesRGB::PaleBlue
FillPatterntype of area fillingSolid
Framesthe number of frames in an animation50
Function1first function/curve delimiting hatch 
HorizontalAlignmenthorizontal alignment of text objects w.r.t. their coordinatesLeft
IntMethodmethod for integral approximationExact
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
LineColorcolor of linesRGB::Black
LineWidthwidth of lines0.35
LineColor2color of linesRGB::Grey
LineStylesolid, dashed or dotted lines?Solid
LinesVisiblevisibility of linesTRUE
LineColorTypeline coloring typesFlat
LineColorFunctionfunctional line coloring 
Namethe name of a plot object (for browser and legend) 
Nodesnumber of subintervals or list of x-values for subintervals[10]
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
PointSizethe size of points1.5
PointStylethe presentation style of pointsFilledCircles
PointsVisiblevisibility of mesh pointsFALSE
ShowInfoInformation about integral approximation[2, IntMethod, Integral]
TextFontfont of text objects[" sans-serif ", 11]
TextRotationrotation of a 2D text0
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
VerticalAlignmentvertical alignment of text objects w.r.t. their coordinatesBottom
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE


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)

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

Error: The first argument must be a 'plot::Function2d' object. [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))

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

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)

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)

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),

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),

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),

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)

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)

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)

delete f:



The integrand: an object of type plot::Function2d.

f is equivalent to the attribute Function1.


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.


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.



Option, specified as IntMethod = m

The quadrature method; see IntMethod

See Also

MuPAD Functions

MuPAD Graphical Primitives

Was this topic helpful?