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;
}
}
Algorithm :-
1. Start
2. Create factorial function fact(int n)
3. return (n==0) || (n==1) ? 1 : n* fact(n-1)
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 nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Translate the following subroutine written in C into ARMassembly code. The parameter x and y are passed to your procedure in register r0 and r1. Your procedureshould place the return value inregister r0. (Note: You must implement the recursive function as defined.) int fun(int x, int y) { if (y <= 0) return 1; else return x*fun(x, y-1); }arrow_forwardNeed help with C++arrow_forwardSML programming Write a recursive function np(n) which takes a non negative n and generates a list of numbers from n+1 down to 0. You may assume that input of n is always valid. Must use identical function name and parameter(s). np(4)⟶[5,4,3,2,1,0]arrow_forward
- In c++ please help me answer this question I will give you a good rating :) implement the three versions of the addupto20() function: iterative, recursive, and divide-and-conquer approach test these functions with a few inputs from your main() Iterative solution * check if there exsits two numbers from vector data that add up to 20 e.g., if data=[2,5,3,15], the function returns true, as data [0] +data [3]==20 e.g., if data=[3,4,0,8], the function return false precondition: vector data has been initialized postcondition: if there are two numbers from list add up to 20, return true; otherwise, return false */ bool AddupTo20 (const vector‹int> & data){ } Come up with a recursive solution to the problem, following the hints given below: * check if there exsits two numbers from vector data[first...right] add up to 20 e.g., if data=[2,5,3,15], first=0, last=3, the function returns true, as data [0] +data [3]==20 e.g., if data=[2,5,3,15], first=2, last=3, the function returns…arrow_forwardMIPS Assembly How would I implement $a0>0 in a recursive function?arrow_forwardWrite a recursive Python function named pgcd, to find and return the Greatest Common Divisor (GCD) of two numbers x and y passed in parameters. • Test it gcd (1234,4321) gcd (8192,192)arrow_forward
- In C++: Explain and show how to use the recursive function int gcd (inta, int b).arrow_forwardLanguage: C++ List two possible causes for infinite recursion. Explainarrow_forwardWrite a recursive function in C++ to multiply all even numbers from 2 to n, where n is an input to the function, and n>=2.arrow_forward
- Find a recursive definition for palindrome.arrow_forwardUse recursive functions only Python only** onlyAU - Given an RNA sequence, returns a new sequence consisting of only the 'A' and 'U' bases from the original sequence with the 'C' and 'G' bases removed. Define onlyAU with 1 parameter Use def to define onlyAU with 1 parameter Do not use any kind of loop Within the definition of onlyAU with 1 parameter, do not use any kind of loop. Use a return statement Within the definition of onlyAU with 1 parameter, use return _ in at least one place. Call onlyAU Within the definition of onlyAU with 1 parameter, call onlyAU in at least one place.arrow_forwardWrite a recursive function definition in C that will calculate the sum of the first n odd integers (all odd interfere between 1 and 2n - 1)arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY