Qbasicnews.com
December 08, 2019, 04:26:56 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 2 [3]
  Print  
Author Topic: Trigonometry  (Read 15678 times)
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #30 on: May 29, 2003, 10:41:59 PM »

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: )
Logged

oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #31 on: June 01, 2003, 11:10:51 PM »

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?
Logged

toonski84
__/--\__
*****
Posts: 2567



« Reply #32 on: June 01, 2003, 11:12:12 PM »

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.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Mango
Wandering Guru
***
Posts: 360



« Reply #33 on: June 02, 2003, 12:05:53 AM »

Quote from: "oracle"
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:
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #34 on: June 02, 2003, 03:15:25 AM »

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?
Logged

Mango
Wandering Guru
***
Posts: 360



« Reply #35 on: June 02, 2003, 11:47:39 AM »

Quote from: "oracle"
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??!!!
Logged
toonski84
__/--\__
*****
Posts: 2567



« Reply #36 on: June 02, 2003, 01:56:58 PM »

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)
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #37 on: June 02, 2003, 11:53:28 PM »

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
Logged

Pages: 1 2 [3]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!