Basic Examples (10)

Approximating Integrals
In Which Integrals Are Approximated

Approximating integrals by various methods: Left boxes, right boxes, upper boxes (new to me!), midpoints, and trapezoids. The partitions may be regular or chosen by the user. I found this lovely worksheet after a few online searches at this site:

https://resources.wolframcloud.com/FunctionRepository/resources/IntegralApproximationPlot

If the actual code is desired, go to the website and click on "Source Notebook."



A left approximation using a regular subdivision with 20 subintervals:

[Sin[(x^2)],{x,0,π},"Left",{"Regular",20}]

An upper approximation using a regular subdivision with 15 subintervals:

[Sin[(x^2)],{x,0,π},"Upper",{"Regular",15}]

Suppress the plot and just return the approximation:

[Sin[(x^2)],{x,0,π},"Upper",{"Regular",15},"DrawGraph"->False]

Specify the mesh size of the partition:

[Sin[(x^2)],{x,0,π},"Midpoint",{"Maxdx",.2}]

The option "Exact" does not apply to partitions containing approximate real numbers:

[Sin[(x^2)],{x,0,π},"Midpoint",{"Maxdx",.2},"Exact"->True]

Return the exact approximation for a partition using exact numbers:

[Sin[(x^2)],{x,0,π},"Midpoint",{"Regular",9},"Exact"->True]

Apply a style to the polynomials used in Simpson’s approximation:

[Sin[(x^2)],{x,0,4},"Simpson",{"Regular",12},"PolyStyle"->{{Orange,Thickness[.02]}}]

Add a style to the filling:

[Sin[(x^2)],{x,0,4},"Simpson",{"Regular",12},"PolyStyle"->{{Orange,Thickness[.02]}},FillingStyle->LightRed]

Use a user-defined partition:

[Sin[(x^2)],{x,0,4},"Left",{0,1/4,3/4,5/4,9/4,3,15/4,4},"Exact"->True]

[Sin[(x^2)],{x,0,4},"Trap",{0,1/4,3/4,5/4,9/4,3,15/4,4},"Exact"->True]

Use Manipulate to illustrate all possible combinations of methods and partitions (except user-defined partitions):

Manipulate[[Sin[(x^2)],{x,0,4},method,If[StringMatchQ[ToString[partition],"Regular"],{"Regular",n},{"Maxdx",dx}],"PrintDisplay"->False,ImageSize->400,Frame->True],{method,{"Left","Midpoint","Right","Upper","Lower","Trap","Simpson","Riemann"}},{partition,{"Regular","Maxdx"}},{n,Range[10,60,10]},{dx,Range[.5,.05,-.05]},SaveDefinitions->True]

Possible Issues (1)

Simpson’s method will not accept a user-defined partition:

[Sin[(x^2)],{x,0,4},"Simpson",{0,1/4,3/4,5/4,9/4,3,15/4,4}]