I'm making an infinite mathematical art graph and it requires calling all values in specific increments. Is there some way to call for, say, all odd integers or all multiples of π? Optimally, I would like to easily customise the increment and it MUST be in the form of an equation.
Repeating values in undefined increments
102 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 2 best solutions below
On
If you want to enumerate all integers in order of their absolute values, you can enumerate the function $$x_n = (-1)^n\lfloor n/2\rfloor$$ for indices $n\geq 1$, where $\lfloor\cdot\rfloor$ is the floor function. (In many computer languages, dividing a positive integer by $2$ will automatically apply the floor function, so you don't have to worry about it.) Here's how $x_n$ works: $$x_1 = (-1)^1\lfloor 1/2\rfloor=-1\times0 = 0$$ $$x_2 = (-1)^2\lfloor 2/2\rfloor=1\times1 = 1$$ $$x_3 = (-1)^3\lfloor 3/2\rfloor=-1\times1 = -1$$ $$x_4 = (-1)^4\lfloor 4/2\rfloor=1\times2 = 2$$ and so on: $(x_n)=(0,1,-1,2,-2,3,-3,4,-4,\ldots)$.
Then you can use this function to generate the related functions you're interested in. In particular, to enumerate odd integers, $$y_n=2x_n+1$$ or to enumerate multiples of $\pi$, $$z_n=x_n\pi$$ or more generally, for all values starting from $b$ with spacing $m$, $$w_n=mx_n+b$$
I do have some experience writing such code! In the illustration for this answer, I needed to enumerate integers in absolute-value order in a few places. It's not too unwieldy to work with.
That said, for your particular application, if you know the bounds for the values in advance, you can write simpler code. For example, let's say you need all multiples of $\pi$ in the range $[-400,400]$. Then you can just enumerate $\pi n$ for all integers $n$ in the range $\big[\lceil -400/\pi\rceil, \lfloor 400/\pi\rfloor\big]$, where $\lceil\cdot\rceil$ is the ceiling function. That's a simpler equation, and the bounds become a simple for-loop in many computer languages.
Well, I figured out an answer eventually. I took the equation $y=sin(x)$ and added the range $\{y=0\}$ to get $y=sin(x)\;\,\{y=0\}$, which contains the points $(\pi k,0)$ where $k$ is any integer. Therefore, to get the points $(kn,0)$ where $n$ is the desired interval and $k$ is any integer, one simply has to do $y=sin(\frac{nx}{\pi}) \;\, \{y=0\}$.