Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The cosine function can be evaluated by the following infinite series: the quest

ID: 3783698 • Letter: T

Question

The cosine function can be evaluated by the following infinite series:

the question in the picture

Please, explain as much as possible:)

The cosine function can be evaluated by the following infinite series: 4! 6! a) Write a MATLAB code to implement this formula so that it computes and prints the value of cos using 5 terms of approximation function above (1 term) cos(x) 1 cos(x) 1 (2 terms 2! x2, x4 cos(x) 1 (3 terms) and so on. Also, compute and display the percent relative error as true series approximation error X100% true b) What is the type of error resulted from this approximation (Name of the error c) Plot your solution for cos(x) in MATLAB and attach the plot.

Explanation / Answer

package chegg.cosine;

import java.util.Scanner;

public class CosineCalculation {

   public static void main(String[] args) {

       int x = 0, term = 0;

       System.out
               .println("Enter the following values which are required to calculate cosines series function : ");
       System.out.println("Press 1 for Continue");
       System.out.println("Press 0 for Exit");
       System.out.println(" ");

       Scanner sc = new Scanner(System.in);

       while (true) {

           String operation = sc.next();

           if (operation.equalsIgnoreCase("0")) {
               System.exit(1);
           } else {
               System.out
                       .println("Enter the value of X and N (Series Term ) ");
               x = sc.nextInt();
               term = sc.nextInt();
               if (x == 0) {
                   System.err
                           .println("illegal value provide of x. Kindly re-enter the postive value for x");
               }
               if (term == 0) {
                   System.err
                           .println("illegal value of series term for which calculation to be . Kindly re-enter the postive value for term ");
               }
               Double result = CosineCalculation
                       .cosineFunctionSeriesEvaluation(x, term);

           }

       }
   }

   public static Double cosineFunctionSeriesEvaluation(int x, int term) {
       double total = 1.0;
       if (term == 1) {
           return 1.0;
       } else {
           for (int i = 1; i < term; i = i + 2) {
               double squr = Math.pow(x, term);
               int factorial = CosineCalculation.factorial(term);
               if (term % 2 == 0) {
                   total = total - (squr / factorial);
               } else {
                   total = total + (squr / factorial);
               }
           }
       }
       System.out.println("Functiona value " + total);
       return total;
   }

   public static int factorial(int number) {
       int i, fact = 1;

       // number for which factorial to be calculated.
       for (i = 1; i <= number; i++) {
           fact = fact * i;
       }

       System.out.println("Factorial of " + number + " is: " + fact);
       return fact;
   }

}

There is one main method which is responsible for calculating series sum.

Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote