# Sine wave - long algorithm :s

by webamoeba
Tags: algorithm, sine, wave
 P: 3 Hi, This maths stuff is tstarting to hurt my head!!! :p Ok, I want to use a sine wave to make objects appear at an increasing rate and then a decreasing rate. e.g. where: y=sin(x) y = interval before next object appears so in Maple that'd be: plot(sin(x)+1,x=Pi/2..Pi+(Pi/2)); Now I want the total of all the equations to = 240: solve(((sin(Pi/2)+1)+(sin(Pi/2)+1))*x=240, x); x comes to 60 in this case. Now I want to alter the equation so as it takes another variable, y, where y = the number of objects (integer >= 0), this does not include the first and last objects. so if y = 1 I would need to add ... (sin((((Pi/2)-(Pi+Pi/2))/y+1)*y) +1) ... if y = 2 I would need to add ... (sin((((Pi/2)-(Pi+Pi/2))/(y-1)+1)*(y-1)) +1) + (sin((((Pi/2)-(Pi+Pi/2))/y+1)*y) +1) ... Is there an easier way to determine x given y? without having to use all of those nasty looking equations!!!! thanks hmmm, not sure that was a very good explanation, take a look at http://www.webamoeba.co.uk/glam/CS1S01/cw2/maths.gif it mite make more sense ;)
 Sci Advisor HW Helper P: 2,002 I honestly have no idea what you're trying to do. Anyway, hopefully the relations: $$\sin(k\pi)=0$$ and $$\sin(\frac{\pi}{2}+k\pi)=(-1)^k$$ where k is any integer, will help.
 Sci Advisor HW Helper P: 2,002 Let me get this straight. So you want the rate to increase in the beginning and decrease near the end. Then the rate be can modelled by a sine from t=0 to t=pi (you can change this later). At t=0, the number of sheep is 0 and at t=pi (to become 10 seconds later) it will be s=N, the total number of sheep. (We'll take the rate to be continuous for now). Then the number of sheep at time t is: $$s(t)=\frac{N}{2}\int_0^t\sin(t')dt'=\frac{N}{2}(1-\cos(t))$$ This function satisfies s(0)=0 and s(t)=N. If you want to go from t=0 to t=T, then it simply becomes: $$s(t)=\frac{N}{2}(1-\cos(\frac{t\pi}{T}))$$ The moments at which a sheep should arrive are thus values of t for which s(t)=1, s(t)=2, s(t)=3 etc.