Mark Ian Posted March 14, 2013 Share Posted March 14, 2013 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 More sharing options...
immortal Posted March 14, 2013 Share Posted March 14, 2013 This is a much better one. http://people.uncw.edu/moyerc/QMTools/home.htm 1 Link to comment Share on other sites More sharing options...
Przemyslaw.Gruchala Posted March 14, 2013 Share Posted March 14, 2013 (edited) 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 March 14, 2013 by Przemyslaw.Gruchala 1 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