# Mathematica Help

## Recommended Posts

Hey guys!

It has been a while since I posted so hopefully this one will be good.

Basically I have a table of prime numbers. What is to write this table as an image - from 1 too 480000 - showing each cell that is a prime as white and the others as black.

So basically I'm cycling the numbers from 1-480000 and if they are prime then I want the cell white and otherwise black. I also want to be able to wrap the table to 800x600 pixels.

Any help appreciated.

##### Share on other sites

I wonder what the picture will look like?

##### Share on other sites

The closest I've got so far is this:

Image[Table[if[PrimeQ[x], 1, 0], {x, 1, 800}, {y, 1, 800}]]

That makes an image but shows each line as either black or white instead of each cell.

I know I need to build a table and put it into the Image function but I can't figure out how to do it.

##### Share on other sites

You want to enumerate the cells in a sensible way, try

PrimeQ[ x+800*(y-1)]

##### Share on other sites

The closest I've got so far is this:

Image[Table[if[PrimeQ[x], 1, 0], {x, 1, 800}, {y, 1, 800}]]

That makes an image but shows each line as either black or white instead of each cell.

I know I need to build a table and put it into the Image function but I can't figure out how to do it.

That's because you're only testing the row number, not the cell. I'd do:

Image[Table[if[PrimeQ[x*800 + y], 1, 0], {x, 0, 799}, {y, 0, 799}]]

I think that gives the right result.

edit: err, wait, that might go vertically instead of horizontally. But you get the idea.

##### Share on other sites

This is the formulation I ended up working with. It does what I need:

Size = 300
Image[Table[if[PrimeQ[y* (Size - 1) + x], 1, 0], {x, 1, Size}, {y, 1, Size}]]

Edit: That actually doesn't seem to work correctly. I may need to do some more work on it.

Edited by RyanJ
##### Share on other sites

II eventually gave up on trying to perfect the formula in Mathematica so I wrote a program to generate the code for me. Here is the resulting image if anyone is interested:

http://bayimg.com/lAlKLaaCp

The highest prime used in this list is 104729.

Fascinating.

##### Share on other sites

I think that is just the rest of the number I chose to fold the lines. When I choose 10 cells per line it doesn't have the horizontal rows like that.

##### Share on other sites

Ryan, I was thinking of the diagonal lines. Presumably, depending ton the grid size you choose, you could get a number of different patterns emerging.

Either way. I was quite pleased to see the result.

Nicely done.

##### Share on other sites

Yeah. I understand what you are saying.

I can upload the C# project if anyone else wants to experiment with it. To see what other things we can do.

Though you would need Mathematica in order to process the codes.

## Create an account

Register a new account