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:
Integrals of complex functions are simplified by approximating integrals of a simplified function using Taylor polynomials. The Taylor series of 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.
- 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 to5
. - The limits of integration;
lim1
andlim2
.
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.