2

My problem is the following: I have a matrix $N$ by $N$ in size. I want to fill it with fractions of $1$ of increasing denominator in relation to their distance from the center of the matrix. The central value is always $1$.

$N$ is always odd.

Example for $N = 3$:

1/12, 1/ 6, 1/12

1/ 6, 1   , 1/ 6

1/12, 1/ 6, 1/12

Proof:

$1/12 * 4 + 1/6 * 4 + 1 = 2$

But what would be the formulaic approach for a, say, $5*5$ matrix?

KappaG3
  • 123
  • what are the restrictions on the matrix? Symmetry? Arithmic sequence? –  Dec 31 '16 at 15:15
  • Ah, I'm sorry, but I don't speak math very well. The values inside the matrix have to be spread out according to their distance from the centre, and their sum (excluding the central value) must always equal 1. – KappaG3 Dec 31 '16 at 15:18
  • Can $N$ be even? If so, what counts as the "center"? – Barry Cipra Dec 31 '16 at 15:18
  • No, $N$ cannot be even. To give a concrete example, the matrix is strictly correlated to a list of neighbours in a cellular automata, so there is always a central value. Again, sorry if I'm being vague. – KappaG3 Dec 31 '16 at 15:20
  • A simple edit, adding "where $N$ is odd" to the first sentence will help. Also, in your example, the numerators are all $1$. Is that important, or just happenstance? – Barry Cipra Dec 31 '16 at 15:22
  • Yes, I've edited the original question. Also yes, the numerators are all 1. – KappaG3 Dec 31 '16 at 15:24
  • 2
    @KappaG3 Just to make sure I understand the question correctly, would the $5 \times 5$ matrix look something like this pattern? – Noble Mushtak Dec 31 '16 at 15:30
  • 1
    Do all entries the same distance from the center have the same value? – marty cohen Dec 31 '16 at 15:30
  • Yes, @NobleMushtak! You hit the nail on the head. I'm sure it's a fairly simple problem to solve, but my wording must be atrocious. – KappaG3 Dec 31 '16 at 15:33
  • 1
    Or perhaps not, considering that the square root of two would be involved. Consider b, for example. – KappaG3 Dec 31 '16 at 15:34
  • @martycohen exactly, like in a circle. – KappaG3 Dec 31 '16 at 15:36

2 Answers2

2

This is not an answer, just an attempt to nail down what the OP is looking for in the $N=5$ case. It sounds like the OP wants a matrix of the form

$$\pmatrix{{1\over e}&{1\over d}&{1\over c}&{1\over d}&{1\over e}\\ {1\over d}&{1\over b}&{1\over a}&{1\over b}&{1\over d}\\ {1\over c}&{1\over a}&1&{1\over a}&{1\over c}\\ {1\over d}&{1\over b}&{1\over a}&{1\over b}&{1\over d}\\ {1\over e}&{1\over d}&{1\over c}&{1\over d}&{1\over e}\\}$$

with positive integers $a\lt b\lt c\lt d\lt e$ such that

$$1+{4\over a}+{4\over b}+{4\over c}+{8\over d}+{4\over e}=2$$

I'm making this community wiki. so if I've misinterpreted, feel free to edit.

Barry Cipra
  • 79,832
  • 1
    I am using taxicab distance in my answer, so my matrix looks like: $$\left[\begin{matrix}\frac 1 d \ \frac 1 c \ \frac 1 b \ \frac 1 c \ \frac 1 d \ \frac 1 c \ \frac 1 b \ \frac 1 a \ \frac 1 b \ \frac 1 c \ \frac 1 b \ \frac 1 a \ 1 \ \frac 1 a \ \frac 1 b \ \frac 1 c \ \frac 1 b \ \frac 1 a \ \frac 1 b \ \frac 1 c \ \frac 1 d \ \frac 1 c \ \frac 1 b \ \frac 1 c \ \frac 1 d\end{matrix}\right]$$ – Noble Mushtak Dec 31 '16 at 15:45
  • Looks right to me! Thank you so much for putting into words what I could not. – KappaG3 Dec 31 '16 at 15:45
  • To explain a little more: Each particle in my system has a value, which we may call "energy". Whenever a function is applied to this particle, it gains a certain amount of energy from its neighbours. The matrix represents the factors of this function for each neighbor. Closer neighbours have to concede more energy than distant neighbours, but the sum of these factors minus the central one (which isn't even considered, actually) must equal 1 because the particle must draw exactly 1 * f(...) energy from its neighbours. – KappaG3 Dec 31 '16 at 15:49
  • 1
    @KappaG3, if you mean Noble Mushtak's pattern instead of mine, please say so. (Note, if you don't require the denominators to be strictly increasing, i.e., $a\le b\le c\le d\le e$, then Noble Mushtak's pattern is a subset of mine.) – Barry Cipra Dec 31 '16 at 15:50
  • No, I think that your pattern is what I'm looking for, because I'm assuming that Euclidean distance is what I need. However, I'm sure that both solutions would work once found - only slightly differently. – KappaG3 Dec 31 '16 at 15:51
  • I swapped $b$ and $c$ because $c$ is closer to the origin than $b$. –  Dec 31 '16 at 16:31
  • @Rahul, nice point. As it happens, it makes no difference for the equation that comes out of it. BTW, by fiddling around, I found one solution: $(a,b,c,d,e)=(6,18,54,288,432)$. – Barry Cipra Dec 31 '16 at 18:18
1

Let's say we have a $2n+1 \times 2n+1$ matrix $A$ with a $1$ in the center, which is $A_{n+1,n+1}$, and $\frac{1}{d\cdot \text{taxicab}(x,y,n+1,n+1)}$ for $A_{x,y}$ for any cell that is not the center. We want all of this to sum to $2$, so without the $1$ in the center, we want the elements to sum to $1$.

In Python, this means:

from fractions import Fraction
def taxicab(a,b,c,d): return abs(a-c)+abs(b-d)
# Set this to any non-negative integer you want:
n = 2
# We need to sum x,y from 1 to 2n+1, inclusive on both ends, which is range(1, 2n+2) in Python
sum([Fraction(1, d*taxicab(x,y,n+1,n+1)) for x in range(1, 2*n+2) for y in range(1, 2*n+2) if (x, y) != (n+1, n+1)]) == 1

All of the terms in the sum have a $\frac{1}{d}$ in them, so we can factor out that $\frac 1 d$ and then multiply both sides by $d$ to get $d$ on the right side. Now, switch both sides of the equation to get:

d = sum([Fraction(1, taxicab(x,y,n+1,n+1)) for x in range(1, 2*n+2) for y in range(1, 2*n+2) if (x, y) != (n+1, n+1)])

And then, we can print out the matrix:

# This prints out d:
print("d =", d)
# This prints out the matrix:
for x in range(1, 2*n+2):
    for y in range(1, 2*n+2):
        # Assume that it's the center and our element is 1:
        this_element = "1"
        # If it's not the center, then change the element accordingly:
        if (x, y) != (n+1, n+1):
            this_element = str(Fraction(1, d*taxicab(x,y,n+1,n+1)))
        print(this_element, end="")
        # For formatting:
        for i in range(10-len(this_element)): print(end=" ")
    # For formatting:
    print("")

For example, for $n=5$, we get $d=\frac{35}{3}$, giving us:

$$\left[\begin{matrix}\frac{3}{140} \ \frac{1}{35} \ \frac{3}{70} \ \frac{1}{35} \ \frac{3}{140} \\ \frac{1}{35} \ \frac{3}{70} \frac{3}{35} \ \frac{3}{70} \ \frac{1}{35} \\ \frac{3}{70} \ \frac{3}{35} \ 1 \ \frac{3}{35} \ \frac{3}{70} \\ \frac{1}{35} \ \frac{3}{70} \frac{3}{35} \ \frac{3}{70} \ \frac{1}{35} \\ \frac{3}{140} \ \frac{1}{35} \ \frac{3}{70} \ \frac{1}{35} \ \frac{3}{140}\end{matrix}\right]$$

Noble Mushtak
  • 18,402
  • 28
  • 44
  • Unfortunately, I am busy right now, so I can't make the algorithm now, but I will try to solve this problem when I have time and if I do, I will edit my answer to post the algorithm in this answer. However, if someone else comes up with an algorithm before I do, then I probably won't try to make my own algorithm. – Noble Mushtak Dec 31 '16 at 15:48
  • @KappaG3 Do you want the answer to be in the form of $\frac 1 {d\cdot \text{taxicab}(x,y,0,0)}$, where $\text{taxicab}(x,y,0,0)=\lvert x \rvert+\lvert y \rvert$? That would make this a lot easier. – Noble Mushtak Dec 31 '16 at 16:30
  • @NobleMushtak Yep, that'll do! I found some values earlier by doing a summation of 1 / taxicab(x, y, 0, 0) and then dividing again by that value. However, I wouldn't know where $d$ came from without the summation. – KappaG3 Dec 31 '16 at 17:04
  • @KappaG3 I have edited my answer with a Python script in it. That can find $d$ given $n$ where $2n+1$ is the side of the matrix. Is this sufficient for your purposes? – Noble Mushtak Dec 31 '16 at 19:31
  • @BarryCipra Thank you again for the catch! My script also outputs $\frac 3 {70}$, so it is not a problem with my script, just with how I copied it down. – Noble Mushtak Dec 31 '16 at 19:50
  • @NobleMushtak, glad to help. I hope the OP will clarify what kind of answer they are looking for. Your inversely-proportional-to-the-taxicab-distance interpretation is very nice, and certainly simpler than the egyptian-fractionesque interpretation I posted on the community wiki. – Barry Cipra Dec 31 '16 at 20:36