Exercise: Integrating Complex Functions

In this exercise, you will implement a Python function to integrate complex mathematical functions.

We'll cover the following


Sometimes the integrals of complex functions are difficult to compute and the result is not as clean. For example:

tan1(x) dx=x tan1(x)12ln(1+x2)+C\int tan^{-1}(x) \space dx=x\space tan^{-1}(x) -\frac{1}{2}ln(1+x^2)+C

Integrals of complex functions are simplified by approximating integrals of a simplified function using Taylor polynomials. The Taylor series of tan1(x)tan^{-1}(x) is given as a simple addition of polynomials.


Let’s apply this in Python as well.

Problem statement

Define a Python function ts_integral() that computes the indefinite or definite integral of the Taylor series from the input mathematical function.

The function should have the following arguments in this order:

Obligatory Arguments - The function should always have these arguments at least.

  1. The mathematical function input: f.
  2. The variable to be integrated: x.

Optional Arguments - the function will input defaults even if the user does not provide these.

  1. The order of the Taylor series expansion n, with the default value set to 5.
  2. The limits of integration; lim1 and lim2.
def ts_integral(f, x, n, lim1, lim2) 

Return Statement

The function should return a tuple with two values:

  1. The Taylor series of the input function.
  2. The integral from the Taylor series of the input function. The value of the integral should be up to 3 significant figures.

Get hands-on with 1200+ tech skills courses.