Jump to content

Understanding Quantum Mechanics Through Code?


Mark Ian

Recommended Posts

I've stumbled upon this quite interesting website (through google admittedly, but I find it nevertheless noteworthy; plus maybe you or someone else knows of similar sites to this one). The website is quite straightfoward, the code is in C and is roughly 3000 words long.

 

 

http://kim.oyhus.no/QuantumMechanicsForProgrammers.html
 

I am not quite sure as how to interpret the code, eventhough it is in code:

 float 
U[ 1000 ][ 1000 ];
...
for(   t=0;  t<1000;  t++)
  for( x=0;  x<1000;  x++)

        U[ t+1 ][ x   ]  =
     -  U[ t-1 ][ x   ]
     +  U[ t   ][ x+1 ]
     +  U[ t   ][ x-1 ] ;

 

 

so we have two while loops with a 2d matrix with time and x, looping a hundredthousand times. Does this return the y position at any given time and x position? and if the piece of code is to define all y positions how can we call a not yet computed y position?

 

note: Im not familiar with C but all languages are quite similar, in my language a matrix is written as U[t,x] for example, but I understand matrices (I think) and use them frequently while programming.

Link to comment
Share on other sites

The all code on his website is tragedy- it's reading from and writing to illegal memory, exceeding array from both sides..

 

If x=0 in first step of for() loop, then U[][x-1] refer to memory location which is at index -1 cell before array, causing exception..

 

Spreading of temperature (the first code in the beginning) is showing equation

 

( temperature of cell 1 + temperature of cell 2 + temperature of cell 3 ) / 3 (3-number of cells that're used simultaneously)

 

so if temperature of cell 1 is 1000, cell 2 is 0, cell 3 = 0

after first t you will have

(1000+0+0)/3=333.3

then in another t, (333.3+333.3+0)/3=222 another cell (333.3+0+0)/3=111

etc. etc. in the next iterations.

 

Temperature of hot cell is increasing temperature of surrounding cells (and decreasing itself), then they're heating surrounding cells and so on, so on, until the all cells have equal temperature.

Spreading of wave is done similar way.

 

The funniest part of his code:

 

"double

U[ 1000 ][ 1000 ][ 1000 ][ 1000 ]; /* Note: 4 dimensions */"

 

It's obvious he never ever tried to compile this code..

Above line of code is allocating memory block of 8 TB (8 terabytes).

Nobody have so much memory in any computer.

Edited by Przemyslaw.Gruchala
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
×
×
  • 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.