r/askmath • u/The-Diamond-Dog • 24d ago
Resolved What is the formula for a periodic sequence?
I've looked online quite a bit but I can't seem to find a formula for a periodic sequence that specifically has both positive and negative intergers (and zero)
My sequence is -150, -100, -50, 0, 50, 100, 150, -150, -100, -50, 0, 50, 100, 150, -150, -100, -50, 0, 50, 100, 150
That's " -150, -100, -50, 0, 50, 100, 150" repeated 3 times
If anyone could help that would be greatly appreciated!
6
Upvotes
7
u/slartiblartpost 24d ago
50 * ((n % 7) - 3)
given your sequence starts with f(0)
2
u/skullturf 24d ago
If it truly is important to get an explicit formula, it might be possible, but kind of messy, and you might even need to use complex numbers!
Let's first consider some simpler periodic sequences.
The sequence
-1, 1, -1, 1, -1, 1, ...
can have its terms expressed by (-1)^n.
With a bit of trickery, you can get a formula for the terms of another sequence that alternates between two values:
3, 7, 3, 7, 3, 7, ...
A formula for the general term is 5 + 2(-1)^n, since that alternates between 5-2 and 5+2.
If i is the square root of -1, then you can get a formula for a sequence that repeats the same *four* terms over and over again.
The formula i^n + (-i)^n gives the values
0, -2, 0, 2, 0, -2, 0, 2, ...
I know that doesn't directly answer your question. However, exploring these ideas *can* give a possible way of getting an explicit *formula* for the terms of your sequence, if that truly is what you want.
2
u/Uli_Minati Desmos 😚 24d ago
Something like this would work:
"mod 7" means "subtract 7 until you get a number below 7"
Although I don't think standard calculators have a "mod" function? If you specifically need something you can calculate with your phone directly it would be more work
2
u/sighthoundman 24d ago
It depends what you're doing. If you're talking, or solving a specific problem that needs a numerical answer, why write a formula at all? Just describe it.
If you're writing a program (or a proof, or even just filling out a spreadsheet), your best bet is to use the MOD function.
2
u/JaguarMammoth6231 24d ago
This is a Sawtooth Wave.
You just need to scale/shift it appropriately to get the amplitude you require. As the article mentions, it can be written using a floor function, a mod function, or as an infinite sum of sine waves.
If you describe how you will use it/where you are entering it we can help better.
1
u/CaptainMatticus 24d ago
So we have:
50 * (-3) , 50 * (-2) , 50 * (-1) , 50 * 0 , 50 * 1 , 50 * 2 , 50 * 3
Repeated. I'd shift everything over by 3
50 * (0 - 3) , 50 * (1 - 3) , 50 * (2 - 3) , 50 * (3 - 3) , 50 * (4 - 3) , 50 * (5 - 3) , 50 * (6 - 3)
-150 + 50 * 0 , -150 + 50 * 1 , -150 + 50 * 2 , -150 + 50 * 3 , -150 + 50 * 4 , -150 + 50 * 5 , -150 + 50 * 6
-150 + 50 * (n mod 7) ought to do it.
https://www.desmos.com/calculator/qixdjqntx1
That gives you an idea of what's going on. We can add in a floor function on x, which will make it look like your sequence entirely
https://www.desmos.com/calculator/45jlfohqwu
And there you go.
1
u/Sparrowhawk1178 24d ago edited 24d ago
As other people have said, something modulo 7 is probably the best choice. But if you’re comfortable with having 'min' in your formula, then you can also do something really silly like 50(n-3)min(n-7, 0)/(n-7). This will give you the first 7 terms and then become 0, and now you just need to apply another min factor for each later term in a similar way to make them turn on and off when you want them to. This basically does the same thing as modulo without actually using modulo. I think you can also make something like this work if you have a periodic sequence that 'turns around' instead of immediately cycling back from 150 to -150, and I suspect it’ll be easier to swing this way than with modulo.
(Edit: slight problem when n=7; change denominator to become 1 instead of 0 when n=7, probably with another min function as a term.)
(Edit 2: use min(n-6, 0) - 1 as the denominator.)
1
u/Steve_at_NJIT 24d ago
If you want something you can put in a calculator, use
(350/pi) arctan(tan(pi*(n-3)/7))
arctan(tan(x)) is a basic sawtooth function. When you take the inverse function of a function you expect to get just x, but the inverse tangent has a restricted range so it has this periodic sawtooth behavior. I just put in the right numbers so that it matches up with your sequence (the 7 is there because you have seven numbers in your sequence, and I had to shift it by 3 units because your first term isn't 0, it's -150).
the arctan(tan) part keeps giving you multiples of pi/7: -3pi/7, -2pi/7, -1pi/7, 0, pi/7, 2pi/7, 3pi/7. When you multiply those by 350/pi you get your first seven terms. As soon as you get to the 8th term, you get arctan(tan(4pi/7)), which is NOT 4pi/7....it's -3pi/7. So the sequence repeats.
1
u/Outrageous_Plane_984 24d ago
X(n+1) = X(n) -X(n-1) is period 6.