News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Trigonometric Function Blues

Started by AMSDOS, 22:04, 20 February 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

For so long I've taken COS 1° as 0.540302305 in Radians and I can get that if I say to my calculator SIN(PI/2-1°), though I'm stumbling what SIN does to that result and I probably did this stuff heaps of times at school and asked myself how's this going to help me in Life.  :( 
It's virtually the same formula to get SIN except you substitute COS for SIN in that problem above.


This is the site I was getting my information at but is there anyway to explain it to an idiot?  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

gerald

I am not sure i got you question but :

with the following identity :
sin(x-y) = sin(x)*cos(y) - cos(y)*sin(y)

with x = pi/2 and y = 1 you get :
sin(pi/2)*cos(1) - cos(pi/2)*sin(y)

Since sin(pi/2) = 1 and cos(pi/2) = 0 you just simplify and end up with :
sin(pi/2-1)=cos(1)

Now, are you trying to get a cos from a sine table ?

AMSDOS

#2
Hi gerald,


More of a matter of getting the result you need (from the long-handed mathematics) instead of getting the result from a cos(1) or sin(1). I actually found the answer from an old post I made a decade ago (on another forum) which resulted in some BASIC subroutines.


Quote
Here another way.... :

Sin function


10 INPUT X#
20 GOSUB 1000
30 PRINT Y#
40 END
1000 REM SIN(X#). X# IN RADIANTS. OUTPUT IN Y#
1010 RESULT# = 0 : SIGN%=-1
1020 DOUBLEPI#=6.283185307#
1030 PRECISION = 50
1040 TEMP% = X#/DOUBLEPI#
1050 X#=X#-TEMP%*DOUBLEPI#
1060 FOR K=1 TO PRECISION
1070 ADDENDUM#=X#
1080 FOR SCANIT=2 TO 2*K+1
1090 PARTQUOT#=X#/SCANIT
1100 ADDENDUM#=ADDENDUM#*PARTQUOT#
1110 NEXT SCANIT
1120 RESULT#=RESULT#+(ADDENDUM#*SIGN%)
1130 SIGN%=SIGN%*-1
1140 NEXT K
1150 Y#=X#+RESULT#
1160 RETURN



and Cos function


10 INPUT X#
20 GOSUB 1000
30 PRINT Y#
40 END
1000 REM COS(X#). X# IN RADIANTS. OUTPUT IN Y#
1010 RESULT# = 0 : SIGN%=-1
1020 DOUBLEPI#=6.283185307#
1030 PRECISION = 50
1040 TEMP% = X#/DOUBLEPI#
1050 X#=X#-TEMP%*DOUBLEPI#
1060 FOR K=1 TO PRECISION
1070 ADDENDUM#=X#
1080 FOR SCANIT=2 TO 2*K
1090 PARTQUOT#=X#/SCANIT
1100 ADDENDUM#=ADDENDUM#*PARTQUOT#
1110 NEXT SCANIT
1120 RESULT#=RESULT#+(ADDENDUM#*SIGN%)
1130 SIGN%=SIGN%*-1
1140 NEXT K
1150 Y#=1+RESULT#
1160 RETURN



Hope those are correct, cause the formatting was a bit funny with Brackets & Column with replaced with control numbers. Maybe because of the Mac.


Though that if I could nut out BCPL which doesn't have COS or SIN, I could draw a Circle in it.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ralferoo

Quote from: AMSDOS on 22:04, 20 February 15
For so long I've taken COS 1° as 0.540302305 in Radians and I can get that if I say to my calculator SIN(PI/2-1°), though I'm stumbling what SIN does to that result and I probably did this stuff heaps of times at school and asked myself how's this going to help me in Life.  :( 
It's virtually the same formula to get SIN except you substitute COS for SIN in that problem above.


This is the site I was getting my information at but is there anyway to explain it to an idiot?  :D
Honestly, that webpage does a much better job of explaining things than I ever could! Just carry on reading that page, but certainly the section "Series Definitions" is probably the information you're after.

Personally, I always find it easier to think of this stuff in terms of complex numbers, although it will seem very complicated at first, especially if the above seems hard. But essentially, you can think of a point on a circle, instead of as being x=r*cos(a), y=r*sin(a), as being p=r*(cos(a)+i*sin(a)). The interesting thing about complex numbers is that i*i = -1. If you look back at the series definitions, you'll see that sin and cos seem to be alternating terms in the same equation. The secret is that if you multiply the sin ones by i and then add them together, you'll see that the equation is sum( (xi)^n/n! ). The special way of writing p is e^(xi) but that requires quite a lot of maths to prove and also it doesn't really help understanding at this point, so maybe just accept that as true for now... :)

Also, if you remember that cos(x)=sin(x + pi/2), you can think of that in the complex plane by looking at the diagram, and think what adding pi/2 to the angle means... it's simply a rotation (generally drawn anticlockwise) of the point. You can also think of it as multiplying by i, which is the same operation, and likewise with the combined equation above (the cos(x)+isin(x) added together) and write it out, you can see how that effectively just shift each term along one and so how the cos turns into a sin.

AMSDOS

Quote from: ralferoo on 10:22, 21 February 15
Honestly, that webpage does a much better job of explaining things than I ever could! Just carry on reading that page, but certainly the section "Series Definitions" is probably the information you're after.


It's a Good page, I didn't mean to make it sound like it was an useless page, simply human error crept in where I presumed a formula could be produced for returning what a COS or SIN would do, but even that site shows variations are used for different angles. And what I needed was a programming solution for that problem, which I found anyway, though the language doesn't support Decimal numbers anyway.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod