# Exercise: Integrating Complex Functions

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

## We'll cover the following

# Task

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

$\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 $tan^{-1}(x)$ is given as a simple addition of polynomials.

$tan^{-1}(x)=x-\frac{x^3}{3}+\frac{x^5}{5}-\frac{x^7}{7}+\frac{x^9}{9}...$

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.

- The mathematical function input:
`f`

. - The variable to be integrated:
`x`

.

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

- The order of the Taylor series expansion
`n`

, with the default value set to`5`

. - 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:

- The Taylor series of the input function.
- 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.