Jump to content

Mathematica Help


RyanJ
 Share

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.

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

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.