Question

The cosine function is analytically defined as follows: m 1. x² + x6 (-1) x2m COS X = (-1) x2n (2n)! 2!*4!- 6 + ... + (2m)!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include<stdio.h>
#include<math.h> //to use pow function

int fact(int n) {
   if(n==0)
       return 1;
   else
       return n*fact(n-1);
}

double cosValue(double x, int m) {
   double sum = 0;
   int i;
   for(i=0;i<=m;i++)
           sum += (pow(-1, i) * pow(x, 2*i))/fact(2*i);
  
   return sum;
}

int main() {
   int m;
   double x;
   printf("Enter x: ");
   scanf("%lf", &x);
  
   printf("\nEnter m: ");
   scanf("%d", &m);
  
   printf("\nResult: %lf", cosValue(x, m));
  
}

OUTPUT

PLEASE MAKE SURE TO LIKE THE ANSWER. THANKS SO MUCH IN ADVANCE :)

Add a comment
Know the answer?
Add Answer to:
The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Take my hyperbolic sin/cos recursive function place the angle on a sine or cosine stack that represents a call to the si...

    Take my hyperbolic sin/cos recursive function place the angle on a sine or cosine stack that represents a call to the sine or cosine. When the program returns, examine the stack for how many times the hyp sine was called and how many times hyp sine/cosine was called vs. the value you inputted into the program. Put the results in a table. Range of values from -1 to 1 in .1 radian increments. Does the number of function calls agree...

  • 3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be...

    3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be evaluated by the following infinite series - equation (2): 1. x² x4 26 (-1)(n+1). 22(n-1) cos x = 1 - 3 + - 6! + + (2(n − 1))! Here are requirements for the function m-file. - Parameter lists (inputs): 2 value (in radian), and desired error percentagel. - Return value (outputs): approximated value, real error percentage, and number of iterations - Function name:...

  • Can you send the code and the screenshot of it running? 1) Create a PYHW2 document...

    Can you send the code and the screenshot of it running? 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both flowchart and pseudocode forms for the following two functions: A. Write a Python function that receives a real number argument representing the sales amount for videos rented so far this month The function asks the user for the number...

  • Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS...

    Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...

  • Problem1. Write a C program, called cos.approx.c, that computes the approximate value of cos(x) according to...

    Problem1. Write a C program, called cos.approx.c, that computes the approximate value of cos(x) according to its Tavlor series expansion: (-1)"r2n (2n)! x2 x4x6x8x10 cos(x)-Σ 1 This series produces the exact value of cos(x) for any real number x, but contains an infinite number of terms. Obviously, a computer program can compute only a finite number of terms. Thus, you will have to truncate the infinite series in (1). Your program should be able to do so in two different...

  • The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at...

    The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at least one root between a = 0 and b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows: a. It finds the midpoint r = (a + b)/2. b. If f(r) = 0, then r is the root. If |b ‐ a| is very small less than ∈ then also we can take r as the root....

  • #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x)...

    #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x)...

  • (1 point) Consider the function f(x) = f* cos(t) – 1 dt. t2 Which of the...

    (1 point) Consider the function f(x) = f* cos(t) – 1 dt. t2 Which of the following is the Taylor Series for f(x) centred at x = 0? w A. (-1)" (2n – 1)(2n)! -x2n- +C. n=0 (-1)"(2n – 2) 2n–3. B. (2n)! n=1 c. Σ (-1)" (2n + 1)! -x2n-2 n=1 D. Š (-1)" -X2n-1 (2n – 1)(2n)! n=1

  • The cosine function can be evaluated by the following infinite series as (where the angle x...

    The cosine function can be evaluated by the following infinite series as (where the angle x is given in radians) cos x =1--+ + 2! 4! 6! Create a second function M-file mycos that takes the angle x (in radians), and returns cos(x) with an absolute iterative error less than 1.0e-18. Test your function to find cosine of ?/2 and 2? Display the Expansion order, and the actual error (absolute error, not the relative one) and iterative error using fprintf...

  • This is the given code: /** * This program uses a Taylor Series to compute a...

    This is the given code: /** * This program uses a Taylor Series to compute a value * of sine. * */ #include<stdlib.h> #include<stdio.h> #include<math.h> /** * A function to compute the factorial function, n!. */ long factorial(int n) { long result = 1, i; for(i=2; i<=n; i++) { result *= i; } return result; } int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: %s x n ", argv[0]); exit(1); } double x = atof(argv[1]); int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT