Taylor Series and Efficient Calculations of Transcendental Functions

Ethan Duckworth, Loyola University Maryland, Mathematics

Author Profile
Initial Publication Date: October 10, 2024

Summary

This module helps students learn/relearn about Taylor series, the remainder theorem, symbolic tools in MATLAB, and writing efficient functions for calculating transcendental functions. Students are reminded about some facts in Calculus, and then given a series of examples for them to work on to develop an efficient program for calculating exp(x). Along the way they will verify their results using graphs, numerical bounds, and timing tools. A homework assignment is included that has similar problems to the in-class student examples, but which cover sin(x).

Share your modifications and improvements to this activity through the Community Contribution Tool »

Learning Goals

Afterthis module a successful student will be able to

  1. Use the Taylor theorem with remainder to predict what degree polynomial will be needed to approximate a function with a desired degree of accuracy
  2. Implement an efficient program to approximate the function on a restricted domain
  3. Implement an efficient program to approximate the function on an extended domain by reducing to calculations in the restricted domain
  4. Test/verify the above results using graphs, timing routines, and numerical comparisons.

Context for Use

This module is for use for a Junior-level class called "Programming in Mathematics". The class assumes students have seen Calculus III and Linear Algebra, and had one Intro to Computer Science class (in Python).  The course teaches students MATLAB, reviews programming techniques, and along the way reviews some mathematical topics they (should have) already learned.

Description and Teaching Materials

The activity consists of slides for roughly two lectures. The lectures have two examples that the instructor leads the students through, and then 6 examples that the students are meant to work on together (in pairs).  The content of the lectures can be summarized as

  • Review Taylor series and Taylor polynomials
  • Learn to use MATLAB taylor command, graph function at Taylor polynomial
  • Students find and graph Taylor polynomial for ex
  • Review/learn about the remainders for Taylor series
  • Students graph the remainder for ex
  • Review/learn about the formula for remainders in Taylor series
  • Students use the formula to get upper bound for error in Taylor approxi- mations of ex, compare with calculated error.
  • Students solve for required degree to make Taylor error bound less than 2 × 1015, then graph to verify.
  • Students write an efficient MATLAB function to approximate ex with high accuracy on a restricted domain. They test and time the program.
  • Students write an efficient MATLAB function to approximate ex on an extended domain by reducing to calculations in the restricted domain. They test and time the program.

The topics in MATLAB that are touched upon in the lectures include the following:

  • Symbolic variables, taylor command, subs command
  • Converting symbolic to double
  • Using loops to produce multiple graphs with figure command
  • Using loops to add multiple curves to single graph with hold on command.
  • Using find command to solve vectorized inequality, using linear index.
  • Using polyval to evaluate a relatively high degree polynomial
  • Writing functions
  • Miscellaneous commands: flip, format, fplot, latex, legend, title,

The files below contain everything to teach the lectures, hand out to the students, a follow up homework, and MATLAB files for the lecture and HW solution

Slides slides.pdf (Acrobat (PDF) 473kB Aug15 24)

Slides "handout mode" slides handout.pdf (Acrobat (PDF) 279kB Aug15 24)

Slides with notes slides with notes.pdf (Acrobat (PDF) 539kB Aug15 24)

HW assignment HW.pdf (Acrobat (PDF) 123kB Aug15 24)

MATLAB for lecture taylor_lecture.mlx (MATLAB Live Script 286kB Aug15 24)

MATLAB Homework Solution HW_on_sine.mlx (MATLAB Live Script 322kB Aug15 24)

Teaching Notes and Tips

I have the students work on the "student examples" in pairs, while I walk around the room and offer help. The students have access to a "handout version" of the in-class slides that I use.  The handout version does not have any solutions for the student examples.

At the end of each class I have the students save their work and upload it into a shared folder so that other students can see the class work, and at the next class they can resume where they left off.  I estimate this module would take two lectures, during which the students will be working together about 75% of the time, and I will be "lecturing" roughly 25% of the time.


Assessment

The homework assignment has 6 problems that are designed to very closely parallel the student examples that were covered in class. In these problems the students will explore the Taylor series for sin(x), determine (and verify) the degree of Taylor polynomial needed to make the error < 0.5e-15.  The students then write a function that can perform the polynomial calculation efficiently for arguments in a restricted domain. Finally, they write a second function that reduces unrestricted arguments to ones in the restricted domain.

I've included a solution for the homework in MATLAB, and students get 5 points for each problem based on whether or not they accomplish the required tasks.