Qbasicnews.com

Full Version: Trigonometry
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Yeah, yeah, it's just that toonski came up with the idea *way* before you, mango :wink: . You didn't get penalized much (as I said in the rules).

I said that code should not be posted, then in a later post after everyone had been saying how smart they were for using COS instead I changed the rules to getting more points if posted but still being able to post your method secretly, like toonski did. Glenn already guessed that toonski used the taylor series though... so not too secret, eh :wink:

Toonski: you got bonus points for "off the top of your head" (remember that? :wink: )
Right, that's it, toonski wins. Here is his program:

Code:
DECLARE FUNCTION sine# (theta#)
DECLARE FUNCTION factorial# (x#)
CLS
pi# = 4 * ATN(1)
q# = sine#(pi# * 2)
PRINT q#

FUNCTION factorial# (x#)
z# = 1
FOR y# = 2 TO x#
  z# = z# * y#
NEXT y#
factorial# = z#
END FUNCTION

FUNCTION sine# (theta#)
x# = 3
z# = theta#
WHILE lz# <> z#
  lz# = z#
  z# = z# - ((theta# ^ x#) / factorial#(x#))
  x# = x# + 2
  z# = z# + ((theta# ^ x#) / factorial#(x#))
  x# = x# + 2
WEND

sine# = z#
END FUNCTION

Congratulations, toonski :king: :king: :bounce: :bounce:

What would you like for winning? Here's a cookie :wink:

Anyone got any complaints?
yeah, the cookie's really yello and has a freakish face on it...

I'd also like 10 bucks. My address has been pm'd to you.
Quote:Right, that's it, toonski wins. Here is his program:

Code:
DECLARE FUNCTION sine# (theta#)
DECLARE FUNCTION factorial# (x#)
CLS
pi# = 4 * ATN(1)
q# = sine#(pi# * 2)
PRINT q#

FUNCTION factorial# (x#)
z# = 1
FOR y# = 2 TO x#
  z# = z# * y#
NEXT y#
factorial# = z#
END FUNCTION

FUNCTION sine# (theta#)
x# = 3
z# = theta#
WHILE lz# <> z#
  lz# = z#
  z# = z# - ((theta# ^ x#) / factorial#(x#))
  x# = x# + 2
  z# = z# + ((theta# ^ x#) / factorial#(x#))
  x# = x# + 2
WEND

sine# = z#
END FUNCTION

Toonski...just to be a punk...This code only calculates sin of 360 deg...and it reports something like 1ee-15 instead of ZERO!!!

And furthermore...if you modified the main module to accept user input for the angle (converted to radians, of course), it still won't work if the angle is not between -360 & 360. Man...this is punk...I don't just want part of toonski's cookie...I WANT IT ALL!!! :bounce:
1e-15 basically is zero if you think about it... if your using this function to calculate sines and plot points you'd need 10^15 horizontal pixels to make the answer wrong by one pixel. You could have some of toonski's cookie: if you had sent in your program earlier... :wink:

toonski: $10 new zealand sound good?
Quote:1e-15 basically is zero if you think about it... if your using this function to calculate sines and plot points you'd need 10^15 horizontal pixels to make the answer wrong by one pixel. You could have some of toonski's cookie: if you had sent in your program earlier... :wink:

toonski: $10 new zealand sound good?

I hope no one asks oracle for a SINE value...your $10 program ain't worth jack. Try modifying the main module of toonskies prog as follows so that it will actually accept user input in degrees:
Code:
DECLARE FUNCTION sine# (theta#)
DECLARE FUNCTION factorial# (x#)
CLS
pi# = 4 * ATN(1)
DO

INPUT "enter an angle in degrees"; a#
angledeg# = a# * pi# / 180   'convert to radians

q# = sine#(angledeg#)
PRINT q#
LOOP

Now...input 45...all is well .707

now input 30....looking good .49999999

Now...input a number like...oh...say 2910. This is equivalent to 30 deg...remember...sin is a periodic function...the size of the input angle size *shouldn't* matter. Also recall that the concept of SIN is based on the unit circle with radius of 1. This radius is the hypotinuse of a right triangle...sin is the opposite length/1. Since 1 is the longest side of a right triangle, one of the shorter sides divided by one cannot possibly be greater than one!!!

Did you do it...and enter 2910 (aka 30)? The winning program (after modification to make it accept user input), oh...wait it needs (*another * modification to convert the angle to radians) returns a value of 80,328...an incorrect answer by 4.9 orders of magnitude...

All I can say is :barf:

Now, oracle...I hate to inform you...you spent your sawbuck on snake-oil!

BTW...just having a bit-of-fun ...no serious insults intended...we're all hoping to learn something here, right??!!!
Only if it's after taxes, oracle.

(and pssst. i wouldnt mark someone off for using a used method. There's only a few good ways to calculate sine, and that's the easiest)
He only got marked down slightly... and besides he submitted ages after the comp started...

Unfortunately due to the US not giving us a trade deal there is a tax on everything we send you guys, so you'll have to make do with $7
Pages: 1 2 3 4