Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Aproximate Sin()

  1. Jul 16, 2003 #1
    Greetings !
    The other day i was fooling around a little with equations, i came up with an equation that (when graphed) look very similiar to the graph of y=Sin() .
    Tell me what you think, and if anyone cares to know how i came up with it, i will tell.
    y = -1[ x/π ]((-4x2/π2) + (x/π)(8[ x/π ] + 4) - 4[ x/π ]([ x/π ] + 1))
    Note that [ x ] means the integer of x.
    Edit :
    π is supposed to be [pi], i don't know why it looks so ugly !
    Last edited: Jul 16, 2003
  2. jcsd
  3. Jul 16, 2003 #2
    Yes, tell us, how did you come up with it? For what values of x does it work for?

    The pi symbol looks ugly because its capitol pi.
  4. Jul 16, 2003 #3


    User Avatar
    Staff Emeritus
    Science Advisor


    For x= pi/2, this formula gives y= -1/2. Doesn't look like sin(x) to me.
  5. Jul 16, 2003 #4
    Actually, the graph is 100% right at n[pi]/2 (where n in an integer), it seems you have a mistake somewhere.
    Let me demonstrate when x = pi/2
    x/pi = pi/2pi = 1/2
    [ x/pi ] = [ pi/2pi ] = [ 1/2 ] = 0
    x2/pi2 = pi2/4pi2 = 1/4
    So :
    y = -10((-4*0.25) + 0.5*(0*8 + 4) + 4*0*(0+1))
    y = 1*(-1 + 0.5*(0 + 4) + 0)
    y = -1 + 4/2
    y = -1 + 2
    y = 1

    I wonder how you got -1/2 ...

    I will tell you how i came up with it, but i unfortunately have no time now, some time soon i will post it here.

    Thanks !
  6. Jul 16, 2003 #5
    Ok, i thought a second about it, maybe saying the [ x ] is the integer of x was misleading.
    What i mean by [ x ] is :
    [ x ] = n , where n in a certain integer that satisfy :
    n <= x < n+1
  7. Jul 16, 2003 #6


    User Avatar
    Staff Emeritus
    Science Advisor

    Well, you're right about pi/2: I wrote a number down wrong.

    This really is a very nice approximation to sin(x).
  8. Jul 16, 2003 #7
    Ok, so now that i have time, i will write down how i came up with the idea.
    It was while i was preparing for my physics exam (i never read the textbook before, this was my first time ), one of the chapters in our textbook talks about simply harmonic motion.
    Now, a simply harmonic motion (sorry if the naming is wrong, but you know it hard to get the right word in English), the force must always be in opposite direction of displacement, and must be proportional to distance between the object and the point of equilibrum.
    At that point, i tried to think, what is the different between the simple harmonic motion in half a cycle, and the motion of an object in ballestic trajectory (ignoring air resistance).
    I tried to think, i reached the conclusion that it must be something related to in which part of the motion the biggest part of change in speed happen.
    I thought, a graph would make everything clearer, so, i tried to graph the motion of a balestic (moving upwards) and simply harmonic motion in half a cycle (distance versus time graph), with the same heighest point, and the same time interval.
    As we know, the motion of an object moving upwards under the effect of gravity in a distance versus time graph is actually a parabola (not sure of the naming, but it can be written as ax2+bx+c).
    So, i took 3 test points, to make my two graphs.
    So, i made a function, called f(x), defined on the interval [0,&pi;]
    I then solved to get the values of a,b and c.
    from the first equation, c=0
    from third equation, a=-b/&pi;
    solve with second equation, b=4/&pi;
    and, a=-4/&pi;2
    Now, i graphed my f(x) on [0,&pi;] and sin(x) on the same interval, they looked very similiar (and i was able to figure out the difference between the two types of motion).
    My next step, to make my f(x) the same as cos(x) on other intevals.
    Now, on the interval [&pi;,2&pi;] is the same as on [0,&pi;], except it will be shifted &pi; to the right, and it will be inverted (or, in other words, multiplied by -1).
    So, on the interval [&pi;,2&pi;] -f(x-&pi;) will almost match sin(x) on the same interval, and so on ...
    Now, i needed a way to the -&pi; jumps each time x gets &pi; bigger.
    I thought, if i found an integer that gets bigger by 1 each time x gets &pi; bigger, i will only need to multiply it by &pi;.
    And [ x/&pi; ] is what i needed, this function gets bigger by 1 each time x gets bigger by &pi; (and on steps).
    So, the function f(x-&pi;[ x /&pi; ]) is almost what we need, it oscilates, and a new half cycle starts every n&pi;, the only problem is getting it up and down.
    We need it up when x is in [ 2n&pi;, 2n&pi; + &pi;] and down when x is in [ 2n&pi; + &pi;, 2n&pi; + 2&pi; ].
    I have been taught the trick of -1n (yes, i was taught it, this is the only thing that i didn't think of), when n is odd the result is -1, when n is even the result is 1.
    So, my last function was -1[ x/&pi; ]f(x-&pi;[ x/&pi; ]), where f(x) = ax2+bx+c, and a=-4/&pi;2, b=4/&pi; , c=0.
    The version of the equation you see in my first post is a simplified one.
    If you have any questions or comment, please feel free to tell them :smile:.
    Thanks for your time all.
    Last edited: Jul 16, 2003
  9. Jul 16, 2003 #8
    Well...it uses the fact that sin(x) can be approximated by a a*x^2+b*x+c function in the vecinity of 0...taylor...the rest is very clever...:)
  10. Jul 17, 2003 #9
    I commend you on the way you came up with a good approximation to sin(x), even if it tends to more complexity than less. From a practical perspective, i'd just use a table look-up (computers often implement the function this way when they need speed).

    But I wanted to comment that you should be using the FLOOR function instead of the INTEGER_PART function.

    For example:
    [-x/pi] = -[x/pi] or for all x

    Which means that from (-pi, 0) your function f(x) is not shifted at all (shift factor of [x/pi] is 0). So the value -pi < x < 0 is plugged into the original function f(x). Using floor will fix this anomaly.

    edit: removed link
    Last edited by a moderator: Jul 17, 2003
  11. Jul 17, 2003 #10
    Well, maybe the way i named the function (i called it Integer function) was wrong, but i think i corrected this in previous post, when i said :
    According to this definition, when x is in (-pi,0) then [ x/pi ] = -1, which makes the shift to the left.
    Right ? (maybe i am missing sth).

    EDIT :
    Thanks suffian for the graph, and thanks all for your time.
    Suffian, you are right, the function makes the whole thing more complicated, but it was fun making it :wink:
    Last edited: Jul 17, 2003
  12. Jul 17, 2003 #11
    oh, sorry, i didn't see that part.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Aproximate Sin()
  1. Sin and Cos (Replies: 7)