analytics

Saturday, February 25, 2012

continuous binary matrix multiplication

Consider these pictures as 100x100 binary matrices, the third picture in the series is when you matrix multiply the first two and take every non-zero cell to be a 1.


Here's another one:




Here's one more:



Recursive matrix

I just wanted to see what this would look like you start with a 3x3 Matrix A:
A   A
  A  
A   A
So A is recursively defined. Each block is a smaller version of A. When you eventually on the computer get down to a size of one pixel you terminate the recursion with:
1      1
    1   
1      1
Where these 1's are black pixels. 
Here's what it looks like:

   

a type of complex plot

I thought of this way to visualize a polynomial with a complex domain and complex range. This is the polynomial x^10-1 with the real and imaginary component of x between -1 and 1 and -1i and 1i respectively. To show the complex output of certain values of x, I colored the pixel as more red the bigger the real component and more green the bigger imaginary component. In computers red and green light mixed together make yellow so bright yellow is where both the real and imaginary component of the function output are 1. Black areas are where the function is closer to -1 in both the real and imaginary component.

 For reference where the function equals 0 will have a color of:

Better would be to use a 4 component color system like CMYK and have more C to be more positive real and more M to be more positive imaginary and Y and K for more negative real and imaginary which could be printed on most printers but what you would see on the computer screen would just be an approximation because the computer only uses 3 components. Then the most black parts would be where the equation equals 0.


Thursday, February 16, 2012

Gravitational mass vs inertial mass

I've heard a lot of physicists and people interested in physics noting that inertial mass and gravitational mass seem to be different phenomena and there's no clear reason why the two should end up being exactly the same magnitude.
  First consider the following thought experiment. Suppose you have two perfectly hard spheres of the same mass that start out a distance apart and gravitationally attract to one another, when they eventually collide they both reverse direction and eventually end up in the same configuration that they started, motionless. All the energy was originally from their potential energy based on gravitational mass, turned into kinetic energy based on inertial mass, and then their gravitational attraction gradually slowed them down to return to the same state.All the while the system as a whole had the same total energy.
  Now if something could have more gravitational mass than inertial mass the balls would attract to one another and collide but not go back to the original state they would bounce a shorter and shorter distance apart each collision until they were eventually fused together. This would result in the final system having less energy than what it started with which in an isolated system can't happen.
  And the opposite is if the gravitational mass were less than the inertial mass then every time they collided they would end up ever farther apart and going faster to get there which would eventually end up with both masses having infinite kinetic energy.
  So you see this thought experiment shows that they have to be the same based on conservation of energy.

Wednesday, February 15, 2012

solving boggle puzzle in the newspaper

Starting with a puzzle like this:
N  N  O  L  H
O  E  H  Y  O
D  I  P  M  C
R  A  M  O  P
E  P  S  H  A

The idea is you make unique words length 3 or greater using each letter at most once and moving through the grid either up, down, left, right, or diagonally from letter to letter to spell out the word.
 I wrote a computer program that searched through a dictionary and found every possible word. It found 741. Here is a list of all the words of 7 or more letters it found:
 AMIDOLS
COMPARE
DAMPENS
EIDOLON
ENHALOS
HEIRDOM
HYPHENS
MADEIRA
MADONNA
MAIDENS
MIDRASH
NONPAID
OOMPAHS
PARAPHS
PARDONS
PERCOID
PHENOLS
POPEDOM
PRIMPED
RAMPION
RAPHIDE
SAPHENA
SARCOID
COMPADRE
DAMPENER
DIAPHONE
DRAMSHOP
EIDOLONS
LYCOPENE
LYMPHOMA
OLYMPIAD
RAMPIONS
SAMPHIRE
SAPHENAE
HOMOPHONE
LYMPHOMAS

My source code in Python:


import copy
class words():
    f = []
        
    def add(self, word):
        print(word)
        self.f.append(word)
    def shut(self):
        r = open("result.txt", "w")
        self.d = set(self.f)
        for word in self.d:
            r.write(word+'\n')
        r.write(str(len(self.f)) + '\n')
        r.close()
result = words()


def check(word, puzzle, pos, n):
    p = puzzle
    p[pos[0]][pos[1]][1] = False
    if n+1 == len(word):
        if len(word) > 2:
            result.add(word)
        return True
    try:
        if (p[pos[0]][pos[1]-1][0] == word[n+1]) and p[pos[0]][pos[1]-1][1] == True:
            check(word, copy.deepcopy(p), [pos[0], pos[1]-1], n+1)
    except:
        pass
    try:
        if (p[pos[0]-1][pos[1]][0] == word[n+1]) and p[pos[0]-1][pos[1]][1] == True:
            check(word, copy.deepcopy(p), [pos[0]-1, pos[1]], n+1)
    except:
        pass
    try:
        if (p[pos[0]-1][pos[1]-1][0] == word[n+1]) and p[pos[0]-1][pos[1]-1][1] == True:
            check(word, copy.deepcopy(p), [pos[0]-1, pos[1]-1], n+1)
    except:
        pass
    try:
        if (p[pos[0]][pos[1]+1][0] == word[n+1]) and p[pos[0]][pos[1]+1][1] == True:
            check(word, copy.deepcopy(p), [pos[0], pos[1]+1], n+1)
    except:
        pass
    try:
        if (p[pos[0]+1][pos[1]][0] == word[n+1]) and p[pos[0]+1][pos[1]][1] == True:
            check(word, copy.deepcopy(p), [pos[0]+1, pos[1]], n+1)
    except:
        pass
    try:
        if (p[pos[0]+1][pos[1]+1][0] == word[n+1]) and p[pos[0]+1][pos[1]+1][1] == True:
            check(word, copy.deepcopy(p), [pos[0]+1, pos[1]+1], n+1)
    except:
        pass
    try:
        if (p[pos[0]+1][pos[1]-1][0] == word[n+1]) and p[pos[0]+1][pos[1]-1][1] == True:
            check(word, copy.deepcopy(p), [pos[0]+1, pos[1]-1], n+1)
    except:
        pass
    try:
        if (p[pos[0]-1][pos[1]+1][0] == word[n+1]) and p[pos[0]-1][pos[1]+1][1] == True:
            check(word, copy.deepcopy(p), [pos[0]-1, pos[1]+1], n+1)
    except:
        pass
    
def main():
    puzzle = [[['N', True], ['N', True], ['O', True], ['L', True], ['H', True]], [['O', True], ['E', True], ['H', True], ['Y', True], ['O', True]], [['D', True], ['I', True], ['P', True], ['M', True], ['C', True]], [['R', True], ['A', True], ['M', True], ['O', True], ['P', True]], [['E', True], ['P', True], ['S', True], ['H', True], ['A', True]]]
    list = open("OWL.txt", "r").readlines()
    for w in list:
        word = w.split()[0]
        for i in range(0, len(puzzle)):
            for j in range(0, len(puzzle[i])):
                if puzzle[i][j][0] == word[0]:
                    inpuzzle = check(word, copy.deepcopy(puzzle), [i,j], 0)
    result.shut()  

Sunday, February 12, 2012

Measuring areas

I had this idea for measuring the area of ordinarily difficult to measure shapes. Consider a simple shape like the following:
You can imagine drawing a line just inside the perimeter of this shape, and then a line just inside that and so on and eventually I believe you will end up with something like a "skeleton" line:

So the perimeter of the skeleton line is 40. It is basically twice the length of the line.  The original perimeter is 46.28. The rule for the area is it is the average of the two perimeters times the thickness around the skeleton. The area of the shape above is (46.28+40)/2 = 43.14*1
If it were twice as thick everywhere it would be times 2 instead of times 1. 

It's easy to verify that the rule works for either a circle or a square where you consider the length of the skeleton to be 0. Also it works for rectangles.  I haven't yet extended it to more complicated shapes. 


Monday, February 6, 2012

bouncing dot analysis

I made a "level" comprised of walls that are either vertical, horizontal or halfway in between. Then you put a point in the level and it can move in one of the basic eight directions one pixel at a time. Then it bounces off the walls like so:
video
You can see it gets back to the original point moving in the same direction and then it repeats about every 30 seconds.  A little bit of analysis shows that what actually happens is there are two points in the pattern where the point completely reverses direction. And a bit of thought can deduce that a necessary condition for that to happen is two walls that can be connected by an uninterrupted line of possible point travel are aligned 45 degrees apart. By the way this video is 5000 frames long. 
   So you can design a level without that necessary condition, one easy way is to avoid diagonal lines in the level altogether so all the levels walls can only be increments of 90 degrees apart. Though I found you have to delete the very corner pixel of each rectangle when using my bouncing algorithm. 

video


In this 5000 frames of video the position and velocity of the point never repeats. It's easy to tell because around 3 minutes in the point eventually squeezed between the top left block and the wall and it never had before that.
  So a good question might be how long it would take to repeat a position moving in the same direction. If I find out I'll update this blog entry.