work and write the cosine function's taylor expansion (N=10) in C++ and compare the with your version (see nartual exponent EXP() vs exp()). EQUATION ATTACHED.    EXAMPLE: #include #include 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'<

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
Transcribed Image Text:(-1)" Σ (2n)! = 1 2! for all a COs x = 4! n=0
Expert Solution
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

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

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