This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Code to model Taylor Series Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Code to model Taylor Series" Watch "Code to model Taylor Series" New topic
Author

Code to model Taylor Series

Amy Lee
Greenhorn

Joined: Nov 02, 2004
Posts: 25
Hello all, I have a question related to code that I'm trying to construct that will model a Taylor series for the sin and cos functions. I've posted to another forum where they were not too friendly...I'm new, so obvious solutions may not be so obvious to me.

That said, the Taylor series for the sin function is:
sin(x) = x - ( x ^ 3 / 3 ! ) + ( x ^ 5 / 5 ! ) - ( x ^ 7 / 7 ! ) + ...

And for cos function it is:
cos(x) = 1 - ( x ^ 2 / 2 ! ) + ( x ^ 4 / 4 ! ) - ( x ^ 6 / 6 ! ) + ...

My code is as follows:


When I would call the method, I would enter x = 90 and numTerms = 10, expecting a return of 1 - instead it returned a huge number: 1.1131025626634878E21.

Someone in another forum told me that I should be entering x as degrees and not radians. When I do this, x = Math.PI / 2.0 and numTerms = 10, it returns 1.0.

Long story short, I want a "second opinion" on my code - is it structured correctly? I know code can be modeled many different ways, but is my way OK? And was the radian thing correct? THANKS!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code to model Taylor Series