6.15.2011

Rookie mistakes

Working on some Poisson solver code today. Made a rookie mistake: used 'x' and 'X' as variables within the same segment of code. They are even related: X is the extent of the device I am simulating, while x is the current position along the device within a loop. I rewrote ~300 lines of code trying to figure out what had gone wrong. Nothing worked.

INCORREC
Then I walked away from the computer and thought about the output. I was seeing this, which isn't totally wrong, but is wrong enough that I was losing my mind trying to figure out.

The key to finding my error was that the error seemed to increase on the right hand side. You can see what look like some 'tearing' up near the top of the image on the right hand side.  The error seems to increase left to right.

CORRECT
The answer isn't that shocking: instead of looping, I was using a fixed value (x versus X), which was causing wrong values to be substituted. Using the right variable yields the right answer. Much better. The Poisson equation is solved!

No comments:

Post a Comment