Question: Write a method to approximate exp(x) = e x by using the Taylor's series expansion. The Taylor's series expansion formula is e x = 1

Write a method to approximate exp(x) = ex by using the Taylor's series expansion. The Taylor's series expansion formula is

ex = 1 + x1/1! + x2/2! + x3/3! + x4/4! + . . .

so for example: e = e1 = 1 + 1 + 1/2! + 1/3! + 1/4! + . . .

(Remember that n! = n * (n-1) * (n-2) * ... * 1.)

Consider how to terminate the loop. A good way to terminate is checking that the recently added term is small enough, smaller than some threshold you have set.

Steps to use:

1. Create a Java file TaylorSeriesForE.java and appropriate class within it.

2. Give your class a method approxmiateE()

This method should have two double parameters x and threshold, in that order.

It should return the double approximation to ex using the Taylor's series expansion above.

Use a do while loop, exiting the loop when the most recently added term is smaller than threshold

3. The Main.java code will instantiate an object from your class, call it with some threshold, and print the output.

4. Do not use Math.E or Math.exp().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!