The function e can be expressed as an infinite power series as follows: 1 2 3! 4
ID: 3733084 • Letter: T
Question
The function e can be expressed as an infinite power series as follows: 1 2 3! 4! or as a general term: ex= 1-0 Since this is an infinite series we will need to decide how far to go to achieve a desired degree of accuracy. The terms in the series get smaller and smaller so the size of the last term used to find the sum, e will be used to decide when we have reached the desired accuracy. Program requirements: Use a main program and two user-defined Function subprograms. In the main program, prompt user in enter a value, x, to use in calculating e. -In the main program, output the answer (the calculated e value) and calculate the ecx) using -Use a user-define Function to calculate a Factorial, N In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value 1 x 107). VBA built-in function and output that answer also (for comparison purposes) Use a user-defined Function to calculate the exponential (e) functionExplanation / Answer
// Java efficient program to calculate e^x
import java.io.*;
class GFG
{
// Function returns approximate value of e^x
// using sum of first n terms of Taylor Series
static float exponential(int n, float x)
{
// initialize sum of series
float sum = 1;
for (int i = n - 1; i > 0; --i )
sum = 1 + x * sum / i;
return sum;
}
// driver program
public static void main (String[] args)
{
int n = 10;
float x = 1;
System.out.println("e^x = "+exponential(n,x));
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.