Author Topic: sine trig function  (Read 10815 times)

kenobe

  • Jr. Member
  • Posts: 66
  • I'm a llama!
    • View Profile
sine trig function
« 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 ???

kenobe

  • Jr. Member
  • Posts: 66
  • I'm a llama!
    • View Profile
trigonometric function
« Reply #1 on: June 06, 2011, 12:06:52 AM »
I would like to know how T100MD handle trigonometric functions

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:sine trig function
« Reply #2 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)

« Last Edit: June 09, 2011, 11:47:49 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

kenobe

  • Jr. Member
  • Posts: 66
  • I'm a llama!
    • View Profile
Re:sine trig function
« Reply #3 on: June 09, 2011, 06:11:11 AM »
understood.
thank you very much