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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started