Internet PLC Forum

General => Technical support => Topic started by: kenobe on June 05, 2011, 12:46:34 AM

Title: sine trig function
Post by: kenobe on June 05, 2011, 12:46:34 AM
can any body please tell me how to calculate the
sine trig function value using TBASIE
Thanks :o ???
Title: trigonometric function
Post by: kenobe on June 06, 2011, 12:06:52 AM
I would like to know how T100MD handle trigonometric functions
Title: Re:sine trig function
Post by: support on June 06, 2011, 09:28:49 AM
Since TBASIC handles only integer there is no built-in Trig or Log functions which are really meant for floating point math.

You could however create a number of data points in a lookup table and search for the nearest 2 data point and use linear interpolation to get a refined result.

E.g. You can store the result of SIN(1) to SIN(90) in DM[1] to DM[90], represent each value as 1/10000.

therefore SIN(30) = 0.5  will be stored as 5000 in DM[30].

Now if you need to find the value of SIN(60.2)

DM[60] = 8660
DM[61] = 8746

 Therefore SIN(60.2) =  8660+ 0.2*(8746-8660) = 8677


i.e. SIN(60.2) is approximated by 0.8677

Calculator check : SIN(60.2) = 0.8678  - not a bad approximation.

So you can write a custom function compute and return the SIN or any angle between 0 to 360 degree using the lookup table.

Note: In TBASIC you need to write the computation as

    R = DM[60]+ 2*(DM[61]-DM[60])/10

(i.e. Multiplication must be before division to maximize the precision)

Title: Re:sine trig function
Post by: kenobe on June 09, 2011, 06:11:11 AM
understood.
thank you very much