Use Python for the programs asked in 1 2 and 3 For each ques

Use Python for the programs asked in (1), (2), and (3)

For each question below, write a small Python (or C, or C++, ...) function. The arguments of the trigonometric functions are angles expressed in radians. How could we compute (cos(x) - 1)/x^2 for values of x that are very close to 0? Use the Taylor series of cos(x) near 0. Compare the Taylor series method with the direct evaluation of the formula (cos(x) - 1)/x^2 (in Python, or C, etc.), when |x| is small. Use the values 10^-6, 10^-10, 10^-16, 0 for x. Similarly, how could we compute sin(x)/x for values of x that are very close to 0? Again, use the Taylor formula. Suppose we have a function s(.) that computes s(x) = sin(x) for 0 lessthanorequalto x lessthanorequalto pi: s(x) is undefined when x

Solution

#include #include using namespace std; double fact (int); double eps; double PI=3.141592654; double fact (int num){ if (num==0 || num==1) return 1; else return num*fact(num-1); } int main(){ double deg; double rad; double term=0.0; double sum=0.0; double cosine=0.0; int i=1; cout<<\"You have chosen to calculate the cosine. Insert degrees of the desired angle: \ \"; cin>>deg; rad=(PI/180)*deg; cout<<\"Value from the c++ library is: \ \"<>eps; while ((cos(rad)-fabs(cosine))>eps){ term=pow(rad,2*i)*((pow(-1.0,i))/fact(2*i)); sum+=term; i++; cosine=sum; } cout<<\"Value of cosine is: \"<
Use Python for the programs asked in (1), (2), and (3) For each question below, write a small Python (or C, or C++, ...) function. The arguments of the trigonom

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site