Results 1 to 7 of 7

Math Help - Need a generic function to perform a task.

  1. #1
    Newbie
    Joined
    Aug 2007
    Posts
    23

    Exclamation Need a generic function to perform a task.

    I need to perform a task using a math function (i'm a programer not a mathematician unfortunately).

    The task i need to perform is to cycle through a list in a sinusoidal motion according to an increasing count.

    the count (time) is increasing at a fixed rate, no problems there, however, I need the number of items in the cycle to change.

    For example I have a 3 item cycle, 1->2->3->2->1->2 etc

    I have managed to write an equation that will give me the result I need for this case:

    y = sin(rad(90)*x)-rad(90))+2

    So if t = x, number of items = 3:

    Code:
    t0 = 1,
    t1 = 2,
    t2 = 3,
    t3 = 2,
    t4 = 1
    (with rounding of the result)

    However, I may need to vary the number of items in the cycle to any arbitrary number, and as such would need for example the following to be true:

    8 items:

    Code:
    t0 = 1,
    t1 = 2,
    t2 = 3,
    t3 = 4,
    t4 = 5,
    t6 = 7,
    t7 = 8,
    t8 = 7,
    t9 = 6,
    t10 = 5,
    ...
    t of 14 = 1
    how would I modify the equation to take into account the number of items in the cycle? (If at all possible)

    Thanks
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Alias_NeO View Post
    I need to perform a task using a math function (i'm a programer not a mathematician unfortunately).

    The task i need to perform is to cycle through a list in a sinusoidal motion according to an increasing count.

    the count (time) is increasing at a fixed rate, no problems there, however, I need the number of items in the cycle to change.

    For example I have a 3 item cycle, 1->2->3->2->1->2 etc

    I have managed to write an equation that will give me the result I need for this case:

    y = sin(rad(90)*x)-rad(90))+2

    So if t = x, number of items = 3:

    Code:
    t0 = 1,
    t1 = 2,
    t2 = 3,
    t3 = 2,
    t4 = 1
    (with rounding of the result)

    However, I may need to vary the number of items in the cycle to any arbitrary number, and as such would need for example the following to be true:

    8 items:

    Code:
    t0 = 1,
    t1 = 2,
    t2 = 3,
    t3 = 4,
    t4 = 5,
    t6 = 7,
    t7 = 8,
    t8 = 7,
    t9 = 6,
    t10 = 5,
    ...
    t of 14 = 1
    how would I modify the equation to take into account the number of items in the cycle? (If at all possible)

    Thanks
    This has nothing to do with sinusoids, you seem to want a sequence which increments/decrements by 1 repeatedly between and upper and lower limit.

    Now why do you want a formula for the n-th term of this why not just generate the sequence programaticaly?

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Aug 2007
    Posts
    23
    Unfortunately, the structure of my application means it cannot be done programatically, there is no fixed number of times the calculation will be performed, nor is the time between calculations fixed and incrementing. I need it to be calculated on the spot according to whatever value of t is passed at the time.

    In other words, as far as my application (abstract and programming) goes, time is not linearly increasing. It could be the same, it could be the same time for 10 or a hundred iterations before time changes.

    It's hard for me to explain unless you can tell me you're a developer and I can use some technical terms?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Junior Member RHandford's Avatar
    Joined
    Sep 2010
    From
    N.E. Lincolnshire
    Posts
    70
    Hi

    I have benn writing apps for may years, so explain away and I will see if I can help
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Aug 2007
    Posts
    23
    I think I may have found a solution using modulus now, but for the sake of completion I'll explain the initial requirement.

    I have a function in my program that is called every time the screen of the device is refreshed, this is an arbitrary, unknown number. Because I don't want the value to increment the function is called, I pass it a "tick" this tick is my "t" above, it checks against this if time has changed or not and calculates the new value accordingly.

    Another method would be for me to store the previous time and check that way and increment if time has changed, but because my class and method are static storage isn't ideal.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,528
    Thanks
    773
    Let a be some parameter. Consider f(n)=a-|(n\mathrel{\mathrm{mod}}2a)-a|. Here n\mathrel{\mathrm{mod}}2a is the remainder when n is divided by 2a.

    Explanation. The absolute value |n| goes down to 0 when n is negative goes back up when n is positive. Next, |n-a| means shifting the graph of |n| to the right a units, so now the value at a is 0. Next, a-|n-a| flips the graph upside down and raises it a units, so now the value at 0 and 2a is 0, and the value at a is a. Finally, replacing n with (n mod 2a) makes the function periodic with the period 2a.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Aug 2007
    Posts
    23
    Quote Originally Posted by emakarov View Post
    Let a be some parameter. Consider f(n)=a-|(n\mathrel{\mathrm{mod}}2a)-a|. Here n\mathrel{\mathrm{mod}}2a is the remainder when n is divided by 2a.

    Explanation. The absolute value |n| goes down to 0 when n is negative goes back up when n is positive. Next, |n-a| means shifting the graph of |n| to the right a units, so now the value at a is 0. Next, a-|n-a| flips the graph upside down and raises it a units, so now the value at 0 and 2a is 0, and the value at a is a. Finally, replacing n with (n mod 2a) makes the function periodic with the period 2a.
    Perfect, that's exactly the modulus function I needed. With a couple of slight changes to shift the values up from zero, that works perfectly. Thanks.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Generic Max/Min process
    Posted in the Geometry Forum
    Replies: 4
    Last Post: August 20th 2010, 09:18 PM
  2. Deriving a generic formula:
    Posted in the Algebra Forum
    Replies: 1
    Last Post: June 21st 2010, 06:27 PM
  3. Generic question on calculus
    Posted in the Calculus Forum
    Replies: 2
    Last Post: May 3rd 2008, 09:19 AM
  4. Generic Summation questions
    Posted in the Calculus Forum
    Replies: 6
    Last Post: April 18th 2008, 04:52 AM
  5. Generic Rectangle help
    Posted in the Algebra Forum
    Replies: 3
    Last Post: March 3rd 2008, 02:25 PM

Search Tags


/mathhelpforum @mathhelpforum