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
There ain't much interest in this, so if I don't recieve another entry within 3 days of now then toonski wins. But its easy to improve what he has done, someone else challenge him.
Code:
DECLARE FUNCTION GetSin# (a#) '*** CHALLENGE ENTRY ***
DECLARE FUNCTION fact# (count&) '*** NEEDED ROUTINE ***

CLS
INPUT "Enter angle in degrees (0 to 360), you wish to calculate sine for: ", a#

si# = GetSin#(a#)

PRINT "QB VALUE= "; SIN(a#)  '*** SHOW QB ANSWER ***
PRINT "MY VALUE= "; si# '*** SHOW MY FUNCTION'S ANSWER ***

WHILE INKEY$ <> "": WEND '*** PAUSE ***
WHILE INKEY$ = "":WEND
SYSTEM

FUNCTION fact# (count&) '*** CALCULATE (2n-1)! ***
     f# = 1
     FOR x& = count& TO 2 STEP -1
          f# = f# * x&
     NEXT x&

     fact# = f#
END FUNCTION

FUNCTION GetSin# (a#)
     pi# = 3.141592653589793#
     a# = a# * (pi# / 180) '*** CONVERT DEGREES TO RADIANS ***

     DO
          n& = n& + 1
          
          p1# = (-1) ^ (n& - 1) '*** DETERMINE + OR - ***
          p2# = a# ^ (2 * (n&) - 1) '*** DETERMINE NUMERATOR ***
          p3# = fact#((2 * (n&)) - 1) '*** DETERMINE DENOMINATOR ***

          s# = s# + p1# * (p2# / p3#) '*** ADJUST SUM ***
     LOOP UNTIL n& > 70

     '*** THE HIGHER n& GOES, THE MORE ACCURATE MY FUNCTION IS***
     '*** HOWEVER, HIGHER n& WILL OVERFLOW THE FACTORIAL :( ***

     GetSin = s#
END FUNCTION

*peace*

Meg.
I have seen it, no time at the mo to give detailed result.
Right, have reviewed it. It's very accurate, but quite long, especially compared to toonski84's entry, which he pm'ed me. Meg gets 21 challenge pts. From this post, everyone has 3 days again to improve, but at the moment toonski84 is still winning.
long code-wise, or long running-time wise? it'd be really easy to make the code shorter (but somewhat less readable).

*peace*

Meg.
Both, but code-wise more.
without the main sub (which mine didn't include), meg's is about the same length in code size.
my routines to calculate *ARC*SIN and *ARC*COS. At any rate, not that I'm doing anything but relieving boredom, I emailed Oracle my version of the type of routine he seemed to be looking for. (Oracle, hopefully you've noticed that some of my comments statements wrapped in the email. You'll have to fix those. I should've zipped it.)
Yeah, I've got it. I'll fix it and post a score here soon.

toonski: you are still winning, but perhaps not for long now you have Glenn on your case :wink: . Try making your one shorter. Same with you, Meg.
Right, no more interest recently, so you all have untill friday morning my time (GMT + 1200, about 40 hours) to submit final entries else toonski wins.
Pages: 1 2 3 4