Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/141-Labs/Lab 09 - Definite Integrals, Riemann Sums, and FTC.ipynb
Views: 491
Lab 09 - Definite Integrals, Riemann Sums, and FTC
Overview
In this lab, we will explore the connection between the definite integral as defined and computed via Riemann sums with the indefinite integral via the Fundamental Theorem of Calculus (FTC).
Important SageMath Commands Introduced in this Lab
ParseError: KaTeX parse error: Undefined control sequence: \hfill at position 32: …|l|l|} \hline \̲h̲f̲i̲l̲l̲ ̲\textbf{Command…Related Course Material
The definite integral of is defined as the limit of Riemann sums To use the above definition to compute or estimate we first choose (the number of subintervals) and set (the length of each subinterval). Next, we need to choose in each subinterval. Some popular choices are the left endpoint, the right endpoint, or the midpoint of each subinterval. We then increase to get better and better approximations. Of course, this leads to messy computations as there are terms in the sum and a closed form is in general very hard to find.
A completely different way to compute definite integrals is to use the FTC, $$\displaystyle \int_a^b f(x) \ dx = F(b) - F(a), \ \ \ \ \text{ where $F(x)f(x)ParseError: KaTeX parse error: Expected 'EOF', got '}' at position 2: .}̲F(x)F(x) = \int f(x) \ dx.$ SageMath is very capable of finding indefinite integrals but don't be surprised if it fails.
Example 1
Let us first experiment with SageMath by having it calculate the Riemann sums of various functions. We will import the function from the package ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{uofsc_̲calculus_labs} which will calculate the Riemann sum of from to using subintervals and using either left endpoints, midpoints, or right endpoints. It will also graph on and graph the rectangles used to calculate the Riemann sum.
To import the function from the package, use the command .
If SageMath returns the error stating that there is no module named ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{uofsc_̲caluculus_labs}, then you will first need to install the package using . This can be done in SageMath by running the command below.
If you are using a lab computer or the Binder server, then you will not be able to use ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{%pip}; however, ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{uofsc_̲calculus_labs} should already be installed.
Once you have the function imported, call the function and use it to approximate the definite integral by calculating Riemann sums. Use various values for to see how larger values of lead to closer approximations for the definite integral.
Now, we will use SageMath to evaluate via the FTC in two different ways and compare the results to our Riemann sum approximations above. First, let us use SageMath to find , an antiderivative of , using the command.
: We know that . However, SageMath says that is an antiderivative of This is because in higher level mathematics, represents the logarithm with base instead of the logarithm with base 10. We can check that this is the case in SageMath by evaluating , which should return 1 if it really is the natural logarithm. Also, even though SageMath uses to mean the natural logarithm, it still recognizes as the natural logarithm.
Therefore, we see that SageMath is telling us that is an antiderivative of Now, we use the FTC to evaluate by calculating .
Remember that we can get a decimal approximation of by either making each term involve floating point numbers, (add a decimal point), or by using the command.
Thus, we have that
Another way in which SageMath can evaluate the definite integral is to use the same command, but with the added parameters of and . Therefore, we will use the command .
Again, we see that
Note: We could make SageMath return the answer in decimal form by using and instead of and .
Notes / Remarks:
As stated in the introduction, it may be impossible to find a closed form of . Try the example .
Both outputs contain the functions and which are not functions with closed form but instead an error function and an infinite series. The good news, however, is that if we use and as our bounds instead of and , then SageMath will use Riemann sums to give an approximation of what the actual answer is.
Therefore, even if it is impossible to find a closed form for an antiderivative of a function, SageMath can still give us a close approximation with very little trouble.
Example 2
For the following functions, use the function to approximate the definite integral using various values of and various endpoint rules. Then, use SageMath to find the exact value for the definite integral and compare with the approximations.