RyanJ Posted April 14, 2010 Share Posted April 14, 2010 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. Link to comment Share on other sites More sharing options...
JohnB Posted April 15, 2010 Share Posted April 15, 2010 I wonder what the picture will look like? Link to comment Share on other sites More sharing options...
Cap'n Refsmmat Posted April 15, 2010 Share Posted April 15, 2010 This looks like what you want: http://reference.wolfram.com/mathematica/tutorial/ImageProcessing.html You can use Table[] to make the matrix of values: http://reference.wolfram.com/mathematica/ref/Table.html Not sure how exactly that'd work, but you can probably work out a way that'll work... Link to comment Share on other sites More sharing options...
RyanJ Posted April 15, 2010 Author Share Posted April 15, 2010 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. Link to comment Share on other sites More sharing options...
the tree Posted April 15, 2010 Share Posted April 15, 2010 You want to enumerate the cells in a sensible way, try PrimeQ[ x+800*(y-1)] Link to comment Share on other sites More sharing options...
Cap'n Refsmmat Posted April 15, 2010 Share Posted April 15, 2010 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. Link to comment Share on other sites More sharing options...
RyanJ Posted April 15, 2010 Author Share Posted April 15, 2010 (edited) 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 April 15, 2010 by RyanJ Link to comment Share on other sites More sharing options...
RyanJ Posted April 18, 2010 Author Share Posted April 18, 2010 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. Link to comment Share on other sites More sharing options...
JohnB Posted April 19, 2010 Share Posted April 19, 2010 Fascinating. The horizontal hold on your Prime numbers needs adjusting. Link to comment Share on other sites More sharing options...
RyanJ Posted April 19, 2010 Author Share Posted April 19, 2010 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. Link to comment Share on other sites More sharing options...
JohnB Posted April 19, 2010 Share Posted April 19, 2010 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. Link to comment Share on other sites More sharing options...
RyanJ Posted April 19, 2010 Author Share Posted April 19, 2010 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now