Name:

Collaborators:

Please list the name of your collaborators.

You will be asked to fill the body of the functions. To make my life (and therefore yours) easier please respect the imput and output of every function. The homework will be graded using a script that test your functions (using the name, input and output I provided here) in a automated fashion.

You saw last time that trying to evaluate $e$, the Euler's number, by a well known limit didn't work well, due to finite precission arithmetics. In this question you will write a function to compute $e$ in a stable manner.

We will use a truncated Taylor series of $e^x$ around 0 which is given by

\begin{equation} e^{x} = \sum_{i = 0}^{\infty} \frac{x^i}{i!}. \end{equation}```
In [ ]:
```function evalExponential(Nterms::Int)
# complete the body of the function
return approxE # return the approximation of e
end

Test your code by running

```
In [ ]:
```evalExponential(10)-e

```
In [ ]:
```import Gadfly
using Gadfly

We compute the relative error for different number of terms and we plot it in semilog scale.

```
In [ ]:
```Error = {abs(evalExponential(ii) -e)/e for ii=1:15}
plot(x = 1:15, y = Error, Scale.y_log10)

Answer:

```
In [ ]:
```function numberTermsForAccuracy(ϵ)
# complete the body of the function
return nTerms # return the number of terms
end

```
In [ ]:
```function evalExponential(ϵ::Float64)
# complete the body of the function
return approxE
end

```
In [ ]:
```function numberTermsForAccuracy(x, ϵ)
# complete the body of the function
return nTerms
end

Q1.e: Write a function to evaluate $e^x$ for any accuracy $\epsilon$.

```
In [ ]:
```function evalExponential(x,ϵ)
# complete the body of the function
return approxE
end

Another important class of algorithms in scientific computing are the root-finding algorithms. They are central for solving algebraic equations, given that any algebraic equation can be translated to a root-finding problem.

for example solving the algebraic equation $x^3 = x +1$, can be translated to find the zeros of the function $f(x) = x^3 -x -1

```
In [ ]:
```function findRootBisection(f,a,b,ϵ, Nmax)
# complete the body of the function
end

To test your function you can define a function, for example:

```
In [ ]:
```function ff(x)
return x^3+0.00001*x^4-0.3
end

And use your root finding algorithm!

```
In [ ]:
```ff(findRootBisection(ff,-1.1,1.4,0.0000001, 30))

This should be really small.

Q2.b In the space below write a script that uses your root finding function to find the solution of the equation \begin{equation} 6(e^x -x) = 7 +3x^2 + 2x^3 \end{equation}

between $[-1,1]$ with a tolerance of $10^{-6}$.

```
In [ ]:
```