0% found this document useful (0 votes)
202 views2 pages

PFC - Workshop 04: Q1 (8 Marks) - Write A Program That Performs The Following Tasks

The document provides the prototypes for 4 functions to calculate exponential, pi, sine and cosine functions approximately using Taylor series expansions. It includes a main function to test the exponential function myExp with 2 prototypes - one calculating up to a given term n, and one calculating until the remainder is less than a given epsilon value. It asks to write the myExp, myPi, mySin and myCos functions based on the given Taylor series approximations and prototypes.

Uploaded by

TV Apeiron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
202 views2 pages

PFC - Workshop 04: Q1 (8 Marks) - Write A Program That Performs The Following Tasks

The document provides the prototypes for 4 functions to calculate exponential, pi, sine and cosine functions approximately using Taylor series expansions. It includes a main function to test the exponential function myExp with 2 prototypes - one calculating up to a given term n, and one calculating until the remainder is less than a given epsilon value. It asks to write the myExp, myPi, mySin and myCos functions based on the given Taylor series approximations and prototypes.

Uploaded by

TV Apeiron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

PFC - Workshop 04

Q1 (8 marks). Write a program that performs the following tasks:


1. Write function with prototype
double myExp(double x, int n);
which calculate ex approximately by the formula:
x x2 xn
ex ~ S = 1+ + + ... +
1! 2! n!
2. Write function with prototype
double myExp(double x, double epsi);
which calculate and return ex approximately by the formula:
x x2 xn
ex ~ S = 1+ + + ... +
1! 2! n!
xn
here n is the first integer for which | |  epsi is satisfied.
n!
You should use the main function below to test your program:
int main()
{system("cls");
double x, epsi; int n;
x = 1.5; epsi = 0.00001; n = 1000;
printf("\n");
printf(" exp(%.1f) = %f\n", x,exp(x));
printf(" exp(%.1f,%d) = %f\n", x, n, myExp(x,n));
printf(" exp(%.1f,%f) = %f\n",x, epsi, myExp(x,epsi));
printf("\n");
system("pause");
return(0);
}

Output for the above main function:

Additional questions (2 marks):


Q2.Write function with prototype:
double myPi(double epsi);
which calculates and return the value PI approximately by the formula:
1 1 1 1
 ~ S = 4* (1- + - +...+(-1)n )
3 5 7 2n  1
1
here n is the first integer for which | |  epsi is satisfied.
2n  1

Q3.Write function with prototype:


double mySin(double x, double epsi);
which calculates and return the value sin(x) approximately by the formula:
x x3 x5 n
x ( 2 n 1)
sin(x) = - + -... +(-1)
1! 3! 5! ( 2n  1)!
1
here n is the first integer for which | |  epsi is satisfied.
2n  1

Q4.Write function with prototype:


double myCos(double x, double epsi);
which calculates and return the value cos(x) approximately by the formula:
2n
x2 x4 x
cos(x) = 1 - + -... +(-1)n
2! 4! ( 2n)!
x 2n
here n is the first integer for which | |  epsi is satisfied.
( 2n)!

You might also like