Question

Take my hyperbolic sin/cos recursive function place the angle on a sine or cosine stack that represents a call to the si...

Take my hyperbolic sin/cos recursive function place the angle on a sine or cosine stack that represents a call to the sine or cosine. When the program returns, examine the stack for how many times the hyp sine was called and how many times hyp sine/cosine was called vs. the value you inputted into the program. Put the results in a table. Range of values from -1 to 1 in .1 radian increments. Does the number of function calls agree with what you predict it should be?

Mentioned code is below *** Answer must be working C++ Code ***

#include
#include
#include
#include
using namespace std;

float h(float);
float g(float);

int main(int argc, char** argv) {
//Testing out recursive trig functions
float angDeg=45;
float angRad=angDeg*atan(1)/45;
cout<<"Angle = "<

0 0
Add a comment Improve this question Transcribed image text
Answer #1

according to Q statement i have calculated number of stack calls from g and h functions


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
int number_of_h=0;
int number_of_g=0;
float g(float angle);
float h(float angle)
{
number_of_h++;
float t = 1e-6;
if (angle > -t && angle < t)
return angle + angle * angle * angle / 6;
return 2 * h(angle / 2) * g(angle / 2);
}
float g(float angle)
{
number_of_g++;
float t = 1e-6;
if (angle > -t && angle < t)
return 1 + angle * angle / 2;
float bd = h(angle / 2);
return 1 + 2 * bd * bd;
}

int main(int argc, char **argv)
{
//Testing out recursive trig functions
float angDeg = 46;
float angRad = angDeg * atan(1) / 45;
number_of_g=0;
number_of_h=0;
cout << "Angle = " << angDeg << " sinh = " << sinh(angRad) << " our h = " << h(angRad) << endl;
cout<<"h\t"<<number_of_h<<endl<<"g\t"<<number_of_g<<endl;
number_of_g=0;
number_of_h=0;
cout << "Angle = " << angDeg << " cosh = " << cosh(angRad) << " our g = " << g(angRad) << endl;
cout<<"h\t"<<number_of_h<<endl<<"g\t"<<number_of_g<<endl;
//Exit stage right
return 0;
}

u.CAU Angle 46 sinh = 0.891923 our h = 0.891923 28656 17710 g Angle = 46 cosh 1.33997 our g 1.33997 17710 10946

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
Take my hyperbolic sin/cos recursive function place the angle on a sine or cosine stack that represents a call to the si...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to...

    Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to calculate the Fibonacci Function 1.) Use a recursive function called fib() to calculate the Fibonacci Function for the following values for the variable n. int n = 10; int n = 20; int n = 30; int n = 40; int n = 45; int n = 46; 2.) In addition to calculating and displaying the results, use a "timer" to see how long...

  • These are my answere to the following questions: are they right? 1. B 2. T 3....

    These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

  • #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part,...

    #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part, your program loads a vending machine serving cold drinks. You start with many foods, some are drinks. Your code loads a vending machine from foods, or, it uses water as a default drink. Create class Drink, make an array of drinks, load it and display it. Part 1 steps: [5 points] Create a class called Drink that contains information about a single drink. Provide...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT