4) Type-generic macro: If the argument has type long double, atanl is called. Otherwise, if the argument has integer type or the type double, atan is called. Otherwise, atanf is called. If the argument is complex, then the macro invokes the corresponding complex function (catanf, catan, catanl). Convert arctan2 to arctan using this formula. And you can then calculate arctan using this infinite series. If you sum sufficient number of terms of this infinite series, you will get very close to what the library function arctan2 does. Here is one similar implementation for exp that you could use as a reference.
Hi everyone,
I am taking a C++ 100 level beginners course and we just got this assgnment that I am stuck on. Here is the assginment description:
We are going to just compute the first 15 or so digits of π using doubles.
In any case, to compute the value of π, we need a formula for it. Let’s use the standard formula,
π = 16arctan(1/5) - 4arctan(1/239)
This is all well and good, but in order to compute π, we need to compute arctan now. We could try to use a standard function from cmath, but let’s write our own function to compute arctan. Mathematicians tell us an easy formula to use is
arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - ...
The only parts that might need some thinking are the alternating signs, and the fact that the exponents and denominators both increment by 2.
Here is a sample output from the program:
Pi = 3.14159265358
Press any key to continue
In class, the professor told us to compare it to the programs we worked on to compute sin(x) and e^x. I have been referring to those programs I have but I still can't seem to solve it. Here is what I have so far:
Dev C++ Arranging Numbers To Ascending
![Dev C++ Arctan Dev C++ Arctan](/uploads/1/2/6/2/126251635/499816516.jpg)
- 3 Contributors
- forum 5 Replies
- 623 Views
- 3 Days Discussion Span
- commentLatest Postby WaltPLatest Post
WaltP2,905
Dev C Arctan And Tan
1) Why calculate the denom and power values from scratch each time? Just add 2 each time through the loop.
Dev C++ 5.11
2) How does
sign*power/denom;
equate to x^5/5
? Where's your x? Where's x^5?