|Chronology||Current Month||Current Thread||Current Date|
|[Year List] [Month List (current year)]||[Date Index] [Thread Index]||[Thread Prev] [Thread Next]||[Date Prev] [Date Next]|
At 06:57 PM 2/5/01 -0500, Ludwik Kowalski wrote:
I could not resist to write a little program .... Monte Carlo approach.
I also couldn't resist writing a little program.
Rather than take the Monte Carlo approach, I took the Finite Element
Modeling approach using a spreadsheet.
Overview: I set up a system to solve Laplace's equation, with more-or-less
any boundary conditions you want. My demo has an odd-shaped object in the
middle, with potential 100 volts, inside a moderately large box at 0 volts.
You can easily change any of these conditions. The machine calculates and
displays the potential at each point.
Just to the right of the "potential" grid there is another grid that
calculates and displays the magnitude of the electric field at each point.
Principle of operation: Consider a cross-shaped group of 5 elements
somewhere on the spreadsheet, and label them as
b w c
Now the discrete approximation to the second derivative in the horizontal
direction is b+c-2w, and in the vertical direction it is a+d-2w. The D=2
Laplacian vanishes if w=(a+b+c+d)/4, i.e. if the central element is equal
to the average of its four neighbors. This leads to an algorithm that says
that for all elements (except for ones that are constrained because they
represent the boundary condition), just set its value to the average of the
four neighbors. After doing this, we have to recalculate the neighbors,
and iterate. For 841 elements (a 29x29 grid) it converges in a few
seconds. That's fast enough that it's not boring, but slow enough that you
can observe the propagation of changes if you fiddle with the boundary
conditions. (Cell V2 at the top of the graph changes the voltage on the
object in my demo.)
Below the potential grid is a graph with many traces; each trace shows the
potential as a function of x; different traces show different y values
(rows). Clicking on one of the traces highlights the corresponding row.
This may help you locate extremal values.
Below the field grid is a similar graph.
Edge effects are nontrivial; if the box were any smaller it would be a
You can make the box bigger by adding more rows and colums if you like;
use the "fill across" and "fill down" features to propagate the vacuum
formula into the new cells. Make sure you fill FROM a vacuum cell that is
NOT ADJACENT to the newly-added cells or the results will be incorrect.
This is for D=2. You could extend it to D=3 in the obvious way: make 29
different 29x29 grids and put the appropriately-generalized formula in them.
The following assumes Excel version 9 (the one that comes with office 2000).
Suggestion: If you are going to seriously play with this, you will want to
play with the spreadsheet's iteration controls. I've got iteration turned
on, and presumably you want to leave it on; hint:
Tools -> Options -> Calculation -> Iteration.
You might want to delay recalculation if you are making numerous changes to
Tools -> Options -> Calculation -> Manual.
which is the opposite of:
Tools -> Options -> Calculation -> Automatic.
And you can invoke the manual "recalculate now" function with the F9 key.
Another small feature uses "Conditional Formatting" to highlight the
contours of potential and field-strength.
Another small feature: You can double-click on a cell, and it will
highlight which cells contribute to the value of that cell. This works
fine for the |field| grid; on the potential grid it is somewhat confusing
because some of the contributor-cells are hidden under the displayed
formula. Clicking puts you into "edit mode" for editing that cell, which is
probably not what you want. Hit "escape" to get out of this mode. It is
less confusing if you format the potential grid as flush-left or
flush-right (not centered) but if you're not using this clicking feature
then centering looks better.