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

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

The document provides instructions to write C functions to calculate exponential, pi, sine and cosine values approximately using Taylor series expansions. It includes: 1. A function prototype and formula to calculate e^x up to the nth term. 2. A function prototype and formula to calculate e^x until the remainder is less than epsilon. 3. Main function to test the e^x functions. 4. Questions to write functions to calculate pi up to a remainder less than epsilon, and sine and cosine up to a remainder less than epsilon, all using Taylor series approximations.

Uploaded by

Fong Nguyen
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)
26 views2 pages

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

The document provides instructions to write C functions to calculate exponential, pi, sine and cosine values approximately using Taylor series expansions. It includes: 1. A function prototype and formula to calculate e^x up to the nth term. 2. A function prototype and formula to calculate e^x until the remainder is less than epsilon. 3. Main function to test the e^x functions. 4. Questions to write functions to calculate pi up to a remainder less than epsilon, and sine and cosine up to a remainder less than epsilon, all using Taylor series approximations.

Uploaded by

Fong Nguyen
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:
E^x ~ S = 1+ x/1! + x/2! + ... + (x^n)/n!

2. Write function with prototype


double myExp(double x, double epsi);
which calculate and return ex approximately by the formula:
ex ~ S = 1+ + + ... +

here n is the first integer for which | |  epsi is satisfied.

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:
 ~ S = 4* (1- + - +...+(-1)n )

here n is the first integer for which | |  epsi is satisfied.

Q3.Write function with prototype:


double mySin(double x, double epsi);
which calculates and return the value sin(x) approximately by the formula:
sin(x) = - + -... +(-1)n

here n is the first integer for which | |  epsi is satisfied.

Q4.Write function with prototype:


double myCos(double x, double epsi);
which calculates and return the value cos(x) approximately by the formula:
cos(x) = 1 - + -... +(-1)n

here n is the first integer for which | |  epsi is satisfied.

You might also like