Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%

work and write the cosine function's taylor expansion (N=10) in C++ and compare the <cmath> with your version (see nartual exponent EXP() vs exp()). EQUATION ATTACHED. 

 

EXAMPLE:

#include <iostream>

#include <cmath>

using namespace std; // lazy technique

// Factorial Recursion.

// https://en.wikipedia.org/wiki/Factorial

// write the factorial function as a loop (iteration)

// This might seem trivial, but people have researched this

// this topic. Sterling series approximation

// https://en.wikipedia.org/wiki/Stirling_approximation int fact(int N) { if (N == 0) return 1; else return N * fact(N - 1); }

// taylor series approximation for the

// natural exponent 2.718... which is abbreviated as exp.

double EXP(double x) { double sum = 0.0;

for (int i = 0; i < 10; i++)

sum += pow(x, i) / fact(i);

return sum; } // dummy--aka place holder--functions.

double SIN(double x) { return 1; }

double COS(double x) { return 0; }

int main() {

std::cout << "e-World!\n";

for (double x = 0.0; x <= 1.0; x += .1) {

cout << x << '\t' << EXP(x)<<'\t'<<exp(x) << endl;

}

(-1)"
Σ
(2n)!
= 1
2!
for all a
COs x =
4!
n=0
expand button
Transcribed Image Text:(-1)" Σ (2n)! = 1 2! for all a COs x = 4! n=0
Expert Solution
Check Mark
Step 1

Algorithm :-

1. Start

2. Create factorial function fact(int n)

3. return (n==0) || (n==1) ? 1 : n* fact(n-1)

4. Create function COS(double x)

5. Run for loop 1 to 10 with increment of 1

6. Return sum+=( pow(x, 2*i) / fact(2*i) )*pow(-1,i) until the loop run

7. Call main function

8. Run for loop for x =0.0 to 1 with the increment of 0.1

9. Print COS(x) function and cos(x) 

10. End

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY