Jump to content

Mathematica Help

Featured Replies

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.

I wonder what the picture will look like?

  • Author

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.

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

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

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.

  • Author

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

  • Author

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.

 

The horizontal hold on your Prime numbers needs adjusting. :D

  • Author

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.

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.

  • Author

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.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.