• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this correct?  RSS feed

 
Lindsey Brooks
Ranch Hand
Posts: 58
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do this:

using java

I don't know if this is correct or not.
Anyone mind checking?

Here is my code:

 
Lindsey Brooks
Ranch Hand
Posts: 58
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind about the first one.

Here is a modified verson:

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lindsey Brooks wrote:
I don't know if this is correct or not.
Anyone mind checking?


Not sure of the issue here? Why can't you check it yourself?

After all, you printed the result. Does it match the result from your calculator?

Henry
 
Lindsey Brooks
Ranch Hand
Posts: 58
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is my algorithm correct?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's up with the math? Your formula is the Taylor's Series of trig functions.

Yet there is another formula (infinite product) using pi and stuff (much more complicated)

As for your algorithm, surely you can randomly check it using the calculator
 
Lindsey Brooks
Ranch Hand
Posts: 58
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just not sure if this is correct or not.

The answer is supposed to be 0.4794255 but I got a negative number. What did I do wrong?


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lindsey Brooks wrote:
The answer is supposed to be 0.4794255 but I got a negative number. What did I do wrong?


Unfortunately, the ranch is a learning site. We are not here to do your homework.

I would recommend testing the two support methods first -- factorial() and power(). Then, after than test the sin() and cos(). For the latter, you can work out each polynomial on paper first (with your calculator), then add print statements in your code to make sure they match. If they don't, you can find the point where they stop matching as you are moving along the polynomial.

Henry
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the original Taylor sequence pic which you pasted, x is supposed to be in radians. I think you've used a number which is in degrees (30) and produced the correct result for 30 radians. But that doesn't match the answer you expected.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!