Calculus Computations using SageMath Calculus


WARNING: THIS PAGE IS UNDER CONSTRUCTION AND IS NOT COMPLETE YET!

As of August 2023. I expect to create it soon. Come back later! Or, email me to get a timeline when I expect to complete it.

SageMath References

Additional SageMath References

  • CoCalc website. A great place to run your SageMath code and save your work.

Your SageMath Computations

Type your own Sage computation below and click “Evaluate”.

Calculus Computations Templates

A few useful things you can do with vectors:

Basic derivatives

Numerical Integration

The definition of the definite integral is: $$ \int_a^b f(x)\, dx = \lim_{n \to \infty} \sum_{i=1}^n f(c_i)\, \Delta x_i, $$ where we may select \(c_i \in [x_{i-1},x_i]\) in any way that we wish.

Left-endpoint Approximation

We pick \(c_i = x_{i-1}\). We also set \(\Delta x_i = \frac{b-a}{b}\), that is, cut \([a,b]\) into $n$ equal pieces. If \(S_n\) is the $n$th Riemann sum, then \(\displaystyle \int_a^b f(x)\, dx \approx S_n\). The formula is: $$ S_n = \sum_{i=1}^n f(c_i) \Delta x_i $$ Next, we have Sage do all the hard work:

Right-endpoint Approximation

We pick \(c_i = x_{i}\) which is the right end point of each subinterval \([x_{i-1},x_i]\).

Midpoint Approximation

We pick \(c_i = \frac{x_{i-1}+x_{i}}{2}\) which is the right end point of each subinterval \([x_{i-1},x_i]\).

Trapezoid Rule Approximation

This time the formula is different. We want the trapezoid above the subinteral \([x_{i-1},x_i]\) with heights \(f(x_{i-1})\) and \(f(x_i)\). Each trapezoid has area $$ \Delta x \cdot \left(\frac{f(x_{i-1})+f(x_i)}{2}\right), $$ which we must sum.

Simpson's Rule Approximation

This one is very interesting since it uses parabolas instead of lines to approximate. Fact: Given three points \(P_0\), \(P_1\), and \(P_2\), there's only one and only one parabola that passes through \(P_0\), \(P_1\), and \(P_2\). Simpson's Rule is based on this fact and uses an EVEN number of subintervals. It uses pairs of consecutive subintervals \([x_{i-1},x_i]\) and \([x_i,x_{i+1}]\) with the three points \((x_{i-1},f(x_{i-1}))\), \((x_{i},f(x_{i}))\), and \((x_{i+1},f(x_{i+1}))\) to generate parabolas that best fit the curve over these two subintervals. See the textbook for the details of the derivation.

Try it!

A few more examples.

Exploration

For the following inquiries, look for non-constant, non-linear functions with the desired qualities.

Inquiry 1

Find a function where the LEA is better than the REA--that is, has smaller error. Then find a function where the REA is better than the LEA.

Inquiry 2

Find a function where the MPA is better than either the LEA or the REA.

Inquiry 3

Find a function where Simpson's Rule is better than the MPA.

Inquiry 4

By taking \([a,b]\) larger and larger, see if you can anticipate what \(\int_{-\infty}^{\infty} e^{-x^2}\, dx\) is. Note: for an exact answer you need Multivarialbe calculus ;-)

Extra-Credit

Write working Sage code that will generate the graphics for the parabolas for Simpson's Rule.

Your Turn