Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sin-1

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
For my GUIs scripting language I want it to be able to do sine-1, does anybody know how to do this? I can't figure out how to do it.
sin-1 is unclear so here's what I mean. I want it to do sine backwards:
sine(1) = .0174
sine-1(.0174) = 1
I also want to do this with tangent and cosine
 
Hi, qbasicking.

Sin-1(x) [or asn(x) as it is known in some versions of Basic] can be calculated from the following series (originally formulated by Sir Isaac Newton more than 300 years ago) :

sin-1(x)=x+1/2*x^3/3+1/2*3/4*x^5/5+1/2*3/4*5/6*x^7/7 ...etc
(where x is in radians)

This may not be the most efficient method of calculating sin-1(x) (there are probably other series that converge more quickly), but it will get you there.

Once you can calculate sin-1(x), you can get the others quite easily:

cos-1(x)=pi/2-sin-1(x), or sin-1[sqr(1-x^2)]

tan-1(x)=sin-1[x/sqr(1+x^2)]
 
You can also hack something up using ATN, the arctangent function. Remember that tan(x) = sin(x) / cos(x), and that cos2(x) + sin2(x) = 1. Then,

cos2(x) = 1 - sin2(x)

cos(x) = (1 - sin2(x))1/2

So,

tan(x) = sin(x) / ((1 - sin2(x))1/2)

Therefore, knowing just sin(x), you can get the value to pass into the arctangent function. Assuming you want to get the arcsine x of a, a is equal to sin(x). Replacing through, we get that:

tan(x) = a / ((1 - a2)1/2)

And therefore:

x = tan-1(a / ((1 - a2)1/2))

The tan-1 function is defined in QB as ATN, so the final code in QB form is:

x = ATN(a / SQR(1 - a ^ 2))

Of course, this only gives you one of the two possible values (when a <> +1). Subtract x from pi to get the other value.
 
also I was wondering, is it possible for qbasic to do logs with bases other than 10?
 
Logarithm identity:

logb a = (log a) / (log b)

Any base at all may be used on the right hand side, as long as it is the same for both logs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top