Trigonometric functions: Difference between revisions

m
Line 966:
 
=={{header|Liberty BASIC}}==
<lang lb>' [RC] Trigonometric functions.
pi = acs(-1)
' Liberty Basic works in radians. All six functions are available.
dtor = pi / 180
' Optional information. You may--
rtod = 180 / pi
' 1. Run as is, for fixed 45 degree 'input'.
radians = pi / 4.0
' 2. Put other degrees ( 0 to 90) into line 2. ( For '90', the tangent = infinity. )
degrees = 45.0
' 3. 'Shorten' decimal places for less accuracy.
' 4. Put radians into line 4. ( 0 to 1.5707963267948966 ). Just delete the 'rem',
' by the Rad example. Now, line 4 data will replace line 2 and 3 data.
2 Deg = 45
3 Rad = Deg / 57.295779513082343
4 rem Rad = 1.27
print "When the angle = "; using("####.###", (Rad) * 57.29577951); " degrees,"
print " (or"; using("###.###############", Rad);" radians), then --"
print
print using( "####.###############", sin( Rad)); " = sine"
print using( "####.###############", cos( Rad)); " = cosine"
print using( "####.##############", tan( Rad)); " = tangent"
print
print " Now the inverses --"
print "For the 'sine' above, the 'arcsine' is --";
print using("####.####", (asn ( sin ( Rad))) * 57.29577951) ; " degrees"
print " ( or," ; using("####.###############",asn ( sin ( Rad)));" radians ) "
print "For the 'cosine' above, the 'arccosine' is --";
print using("####.####", (acs ( cos ( Rad))) * 57.29577951) ; " degrees"
print " ( or," ; using("####.###############",acs ( cos ( Rad)));" radians ) "
print "For the 'tangent' above, the 'arctangent' is --";
print using("####.####", (atn ( tan ( Rad))) * 57.29577951) ; " degrees"
print " ( or," ; using("####.###############",atn ( tan ( Rad)));" radians ) "
 
'LB works in radians, so degrees require conversion
'----------- Output -------------
'All three functions are available.
'When the angle = 45.000 degrees,
print SIN(radians), SIN(degrees*dtor)
' (or 0.785398163397448 radians), then --
print COS(radians), COS(degrees*dtor)
'
print TAN(radians), TAN(degrees*dtor)
' 0.707106781186547 = sine
'as well as inverse functions
' 0.707106781186548 = cosine
print ASN(SIN(radians)), ASN(SIN(degrees*dtor))*rtod
' 1.00000000000000 = tangent
print ACS(COS(radians)), ACS(COS(degrees*dtor))*rtod
'
print ATN(TAN(radians)), ATN(TAN(degrees*dtor))*rtod
' Now the inverses --
'For the 'sine' above, the 'arcsine' is -- 45.0000 degrees
' ( or, 0.785398163397448 radians )
'For the 'cosine' above, the 'arccosine' is -- 45.0000 degrees
' ( or, 0.785398163397448 radians )
'For the 'tangent' above, the 'arctangent' is -- 45.0000 degrees
' ( or, 0.785398163397448 radians )
end
</lang>
Anonymous user