Question: The value ex can be approximated by the following sum: 1 + x + x^2 /2! + x^3 /3! + + x^n /n! The expression

The value ex can be approximated by the following sum: 1 + x + x^2 /2! + x^3 /3! + + x^n /n! The expression n! is called the factorial of n and is defined as: n! = 1*2*3* *n.

Write a program using java that takes a value of x as input and outputs four approximations of e^x done using four different values of n: 5, 10, 50, and 100. Output the value of x the user entered and the set of all four approximations into the screen. Sample formula use: calculating e7 using approximation with n = 5 1 + 7 + 7^2 /2! + 7^3 /3! + 7^4 /4! + 7^5 /5!

Requirements 1. Input validation is needed - do not allow the user to enter anything but integer. Use exception-handling technique discussed in class and implemented in InputValidation.java example to complete the feature.

2. Please do not do any calculations by writing out the entire sums by hand, use loops and running total calculations instead.

3. Factorial function produces large numbers and it grows very quickly. If you start using regular integers to store factorials, youll get integer overflows easily. I would suggest using long to store factorials. On top of that, I would recommend to adjust your calculations in such a way that you never get to calculate the actual factorial values. Look at the pattern in the sum: each next term of the sum can be derived from the previous one by means of a very simple calculation.

4. Test your code. Make sure the calculations are correct by checking the actual values of e^x online. The bigger the value of n the closer the resulting value must be to the actual value of ex.

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!