The value of cos(x) is evaluated as follows: cos(x)=1- x^2/2!+ x^4/4!- x^6/6!+ x^8/8!+⋯+ x^2n/((2n)!) Where n is related to the accuracy level required for cos(x). Write a C++ program that asks the user to input n and x and then the program will evaluate cos(x) up to the 2n terms.
Solution:
#include<iostream>
#include<math.h>
using namespace std;
//method to calculate factorial
unsigned long long fact(unsigned long long n)
{
if(n==1)return 1;
return n*fact(n-1);
}
//method to compute cos(x)
double cos(unsigned long long n,double x)
{
double sum=1;
unsigned long i=2;
while(i<=(2*n))
{
double nume=pow(x,i);
unsigned long long d = fact(i);
//cout<<d<<endl;
//finding term value
nume = nume/d;
if(i%2==0)
{
sum=sum-nume;
}
else
{
sum=sum+nume;
}
i=i+2;
}
//returning sum
return sum;
}
int main()
{
//testing method
//reading input
unsigned long long n;
double x;
cout<<"Enter n and x:";
cin>>n>>x;
//displaying output
cout<<"cos("<<x<<") = "<<cos(n,x)<<endl;
return 0;
}
The value of cos(x) is evaluated as follows: cos(x)=1- x^2/2!+ x^4/4!- x^6/6!+ x^8/8!+⋯+ x^2n/((2n)!) Where n...
The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS X = (-1)" x2n (2n)! 2!*4!- 6 + ... + (2m)! Write a complete C program that has three functions: main, cosine, and factorial. The cosine function receives a real number x and returns a real number representing the cosine of x. The cosine function also receives another integer m that determines the number of terms that will be used in computing the cosine...
a.) Write a C++ program that calculates the value of the series sin x and cos x, sin 2x or cos 2x where the user enters the value of x (in degrees) and n the number of terms in the series. For example, if n= 5, the program should calculate the sum of 5 terms in the series for a given values of x. The program should use switch statements to determine the choice sin x AND cos x, sin...
Recall that, for all c, = n=0 cos(x) = § 4 (-1)",21 (2n)! and sin(x) = (-1)"..2n+1 (2n + 1)! N=0 n=0 If i is defined to have the property that i = -1, show that ei cos(2) + isin(x) for any real number r.
Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o E- (-1) . 2n +1 no (2n+1)! !57 where x is in radians. Write a MATLAB program that determines sin(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a while loop for adding the terms of the Taylor series. If an n is the nth term in...
2) Given that 4 cos[(2n + 1)x] |x| = = = - - nao ,- < x <te. (2n + 1)2 Find the Fourier series of g(x) = -1 1 -1 < x < 0 0 < x <TE 1
n=0 4. Using the power series cos(x) = { (-1)",2 (-0<x<0), to find a power (2n)! series for the function f(x) = sin(x) sin(3x) and its interval of convergence. 23 Find the power series representation for the function f(2) and its interval (3x - 2) of convergence. 5. +
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...
T 4 Σ cos(2n-1)x 2 (2n-1) 1 on interval [, II, ]. Use this to find the value of the infinite sum 1+. 9 25 1 + + 1 49 + I....
Consider the equation f(x) = 2*sin(pi*x) + 3*cos(pi*x) Write a c program that computes the values of f(x) for the following values of x: 0.25, 0.5, 1, 2. Your program should allow the user to enter the value from the standard input and the results will be displayed as follows: /*****************************************************************/ Value of x Value of f(x) 0.25 3.5355 0.5 1 2
Given x(z) = (zˆ2+1)/(z-1/2) Find y(n) = x(2n).(1/2)ˆn and w(n) = cos(pi.n/2).x(n)