Assignment 3

Solution

Important dates

Assigned28 Feb 2017 @ 23:30h
Due8 Mar 2017 @ 23:59h

Description

Implement a Taylor series approximation of some mathematical functions.

In mathematics, Taylor series is a way of approximating transcendental functions such as $\sin x$ or $\log x$. In this approach, we can approximate a mathematical function as closely as we might want to by adding together numbers that get us closer and closer to the true value of the function. For example, the exponential function $e^x$ can be approximated as:

$$ e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots = \sum_{n=0}^{\infty} \frac{x^n}{n!} $$

and the $\sin$ function can be approximated as:

$$ \sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \cdots = \sum_{n=0}^{\infty} \frac{(-1)^n)}{(2n+1)!)} x^{2n+1} $$

The more terms we include in our approximation, the better an approximation we get of $\sin x$. In this assignment, you must implement Taylor series approximations for these two functions. Your functions should take two parameters: the value of $x$ and the number of terms to use in the approximation. For example, when my test code calls approxExp(2.2, 4), you should return the sum of the first four terms of the $e^x$ approximation, i.e.:

$$ 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} = 1 + (2.2) + \frac{(2.2)^2}{2!} + \frac{(2.2)^3}{3!} $$

I will provide you with declarations in the file assign3.h; your source file should #include "assign3.h" and not modify it. You should only submit your source (i.e., .cpp) file. The header file is given below: