Question

In: Computer Science

The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1...

The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1 + ? + ? 2 2! + ? 3 3! + ? 4 4! + ⋯ + ? ? ?! This natural exponential function uses the irrational number ? as a base. You can find the number ? in Java as ???ℎ. ?, as well as, the exponential method as ???ℎ. ???(). You will implement your own exponential method following these criteria: 1. Determine the best returning datatype for your method. Remember it is an exponential function, as so, it grows very fast.

2. Make it public static and accept one parameter: x, as found in the formula above. Create your own method for calculating the factorial and invoke it from your exponential method as needed.

3. For testing purposes, you can match the results of your method to ???ℎ. ? while keeping your argument fixed as 1, e.g., exponential(1). Start by calculating only 5 terms of your series. Then extend the number of terms to 10, 15 and 20. In each case, provide a snapshot of the results where your calculated value appears in parallel with ???ℎ. ?.

4. Repeat the process followed in the previous item but this time compare results with 15, 16, 17, 18, 19 and 20 terms. In each case, provide a snapshot of the results where your calculated value appears in parallel with ???ℎ. ?.

5. How many iterations (addition of terms) did your method require to converge? You know your method converged when the values stop changing as more terms are added.

6. Provide some recommendations on how to improve your method without the experimental process of running for a specific number of iterations.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import java.math.*;

class Maclaurin {

  //method to compute the factorial
  public static int myFactorial(int n) {
    int facto = 1;
    for (int i = 1; i <= n; i++) {
      facto = facto * i;
    }
    return facto;
  }

  //method to compute the Maclaurin series expansion
  public static double Maclaurinseries(double x) {
    double myExp = 1;
    //set the value of n
    //vary this vlaue to generate various n
    int n = 5;
    System.out.println("The value of n= " + n);

    //to sum the various terms upto n
    for (int i = 1; i <= n; i++) {
      double xi = x;

      //for loop to compute the powers of x
      for (int j = 1; j < i; j++) {
        //compute the power of x
        xi = xi * x;
      }

      //find the current term
      double cu = xi / myFactorial(i);

      //the my exponent term
      myExp = myExp + cu;
    }
    //return the exponent value
    return myExp;
  }

  public static void main(String[] args) {
    //call the method
    System.out.println(
      "The Maclaurin series value of e= " + Maclaurinseries(1)
    );
    System.out.println("The actual value= " + Math.exp(1));
  }
}

Related Solutions

The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1...
The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1 + ? + ? 2 2! + ? 3 3! + ? 4 4! + ⋯ + ? ? ?! This natural exponential function uses the irrational number ? as a base. You can find the number ? in Java as ???ℎ. ?, as well as, the exponential method as ???ℎ. ???(). You will implement your own exponential method following these criteria: 1. Determine...
The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1...
The following is the Maclaurin expansion series for calculating ? ? : ? ? = 1 + ? + ? 2 2! + ? 3 3! + ? 4 4! + ⋯ + ? ? ?! This natural exponential function uses the irrational number ? as a base. You can find the number ? in Java as ???ℎ. ?, as well as, the exponential method as ???ℎ. ???(). You will implement your own exponential method following these criteria: 1. Determine...
3. Find the first three nonzero terms of the Maclaurin series expansion for the following function....
3. Find the first three nonzero terms of the Maclaurin series expansion for the following function. (10 Points) ?(?) = ?^cosx
3. Find the first three nonzero terms of the Maclaurin series expansion for the following function....
3. Find the first three nonzero terms of the Maclaurin series expansion for the following function. (10 Points) ?(?) = ?^cosx
2. Do the Maclaurin series expansion of 1 √(1−?) out to 3 terms 3. Find the...
2. Do the Maclaurin series expansion of 1 √(1−?) out to 3 terms 3. Find the Taylor series for the two functions: i. ?(?) = ? −6? about ? = −4 ii. ?(?) = 7 ? 4 about ? = −3
Maclaurin Series
Find the Maclaurin Series of the following functions: (a) f(x)= Ln(3+x) (b) f(x)= cos(3x) (c) f(x) = x^(2)(e^(-x))
maclaurin series
maclaurin series
Find the Maclaurin series for tan x and using that series, derive the Maclaurin series for...
Find the Maclaurin series for tan x and using that series, derive the Maclaurin series for sec^2(x)
Find the Maclaurin series using the definition of a Maclaurin series as well as the interval...
Find the Maclaurin series using the definition of a Maclaurin series as well as the interval of convergence. a) f(x) = 1/((1-x/3)^2) b) f(x) = sin(2x)
Develop a well-structured MATLAB function to compute the Maclaurin series expansion for the cosine function and...
Develop a well-structured MATLAB function to compute the Maclaurin series expansion for the cosine function and name the function cosMac. The function should have the following features: Iterate until the relative error (variable name “relErr” ) falls below a stopping criterion OR exceeds a maximum number of iterations (variable name“maxIter”) for a given value of x. Include a default value of relErr = 1e-6 if the user does not enter the value (use nargin function). Include a default value for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT