Qbasicnews.com
May 27, 2020, 01:47:16 AM
 Pages: [1] 2 3
 Author Topic: Trigonometry  (Read 16196 times)
oracle
*/-\*

Posts: 3652

 « on: May 14, 2003, 09:56:07 PM »

Make a program that calculates the sine of an angle without using the SIN function. Here are the rules:

No SIN function (duh)
Like the statistical challenge, make it as a function
Hardware stuff is allowed, libs are not
It should be accurate to at least 8sf
Points will be awarded for speed and size of code as well as accuracy

Do not post code here just yet, or post hints, but email me the prog (twotowers@ihug.co.nz).

If there is little interest, the rules will change. Have fun!
 Logged

wizardlife
Na_th_an

Posts: 1456

 « Reply #1 on: May 14, 2003, 11:44:16 PM »

Um, that's really easy if you can use the other trig ratios...
 Logged

na_th_an
*/-\*

Posts: 8244

 « Reply #2 on: May 14, 2003, 11:49:54 PM »

Yep. TAN(a) = SIN(a)/COS(a), so it is not a very difficult task.

Also, having to email the proggie is a bummer ... why not posting it here? (I have to open hotmail, blah blah blah and it always works bad)
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
wizardlife
Na_th_an

Posts: 1456

 « Reply #3 on: May 15, 2003, 12:21:55 AM »

Quote from: "na_th_an"
Yep. TAN(a) = SIN(a)/COS(a), so it is not a very difficult task.

Also, having to email the proggie is a bummer ... why not posting it here? (I have to open hotmail, blah blah blah and it always works bad)

OH NOES!11!!!11!

OMG you gave away the secret answer!!!1!!1!

Actually I'd forgotten that QB actually has a TAN function. I think the Pascal manual instructs you to calculate a TAN using SIN/COS, which I always thought of as rather inefficient... fortunately you'd never in a practical situation use anything but SIN, COS, and ATN.
 Logged

toonski84
__/--\__

Posts: 2567

 « Reply #4 on: May 15, 2003, 12:48:08 AM »

well, while we're giving away "secret" trig identities, here's a good one:

sin(theta) = cos(.5pi - theta)
 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
relsoft
*/-\*

Posts: 3927

 « Reply #5 on: May 15, 2003, 12:55:34 AM »

Paging Glenn......
Paging Glenn......

Paging Glenn..... To post his "False Positioning" method of solving Trig functions..... Paging Glenn.....

:*)
 Logged

y smiley is 24 bit.

Genso's Junkyard:
http://rel.betterwebber.com/
wizardlife
Na_th_an

Posts: 1456

 « Reply #6 on: May 15, 2003, 01:02:43 AM »

Quote from: "toonski84"
well, while we're giving away "secret" trig identities, here's a good one:

sin(theta) = cos(.5pi - theta)

OH NOES!!11!!1!!!

sin ^ 2 = 1 - cos ^ 2
 Logged

oracle
*/-\*

Posts: 3652

 « Reply #7 on: May 15, 2003, 06:39:29 PM »

OK, since you guys are being such smarta\$\$e\$... sorry, it's really my fault. Revised rules:

No trig functions. I want to see the *real* way that the sin function is calculated. Go out and Google it to see if you can find the real way.

The reason I don't want people posting code is because once someone finds the *real* way then everyone else is gonna just rip it.

Wait, no... I forgot.

I am rating this challenge through an arbitary method where each entry gains "challenge points". This simply means that if you submit a good entry, you will gain many challenge points, and if you submit something bad you won't gain as many. The measure is *completely* arbitary, so don't go submitting something really bad loads of times to try to get heaps of points. In any event, you can now post code here, but do it quick cos the actual formula is worth loads of challenge points.

Toonski84 is the leader, he submitted the code that made me realise that the challenge rules wern't up to scratch. But it works so he has 3 challenge points, he is winning.

ps: alternatively, you can submit code to me, I will review it and tell you how much you get, and your method stays secret. However, you risk someone else finding the formula and displaying it to the world and gaining big points if you do this.

Once again, sorry about the rules. Now get posting!
 Logged

relsoft
*/-\*

Posts: 3927

 « Reply #8 on: May 16, 2003, 12:15:35 AM »

 Logged

y smiley is 24 bit.

Genso's Junkyard:
http://rel.betterwebber.com/
oracle
*/-\*

Posts: 3652

 « Reply #9 on: May 16, 2003, 01:07:04 AM »

Maybe he sent it in privately. Or maybe he didn't...

Just send them in guys!

I'm reviewing toonski's second entry as I do this!
 Logged

oracle
*/-\*

Posts: 3652

 « Reply #10 on: May 19, 2003, 10:36:34 PM »

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

Meg
Ancient QBer

Posts: 483

 « Reply #11 on: May 20, 2003, 12:28:32 AM »

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.
 Logged
oracle
*/-\*

Posts: 3652

 « Reply #12 on: May 20, 2003, 03:17:41 AM »

I have seen it, no time at the mo to give detailed result.
 Logged

oracle
*/-\*

Posts: 3652

 « Reply #13 on: May 20, 2003, 11:43:31 PM »

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

Meg
Ancient QBer

Posts: 483

 « Reply #14 on: May 21, 2003, 01:22:10 AM »

long code-wise, or long running-time wise?  it'd be really easy to make the code shorter (but somewhat less readable).

*peace*

Meg.
 Logged
 Pages: [1] 2 3