- #1
Rapier
- 87
- 0
Homework Statement
The task is to plot a 2-d surface of the potential and field lines calculated from a numerical method. In this case, there is a charged box (v = 1) @ r = 1 (it's not round, but each side is d = 2 and the center of the box is at the origin) and the edges of the box are v=0. My plan was to use symmetry so that I only have to do the calculations for Quadrant I and then I could do some trickery to set those values for the other quadrants.
Homework Equations
N/A
The Attempt at a Solution
My initial conditions work correctly and I get (exactly what I expected):
--------Initial Conditions--------
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
At the end of my numerical method I have the correct field values in my 2-d array.
--------Final Conditions--------
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.02 0.02 0.02 0.02 0.01 0.01 0.01 0.00 0.00 0.00
0.04 0.04 0.04 0.03 0.03 0.02 0.01 0.01 0.00 0.00
0.08 0.08 0.07 0.06 0.04 0.03 0.02 0.01 0.01 0.00
0.14 0.14 0.12 0.09 0.07 0.04 0.03 0.02 0.01 0.00
0.24 0.23 0.19 0.14 0.09 0.06 0.04 0.02 0.01 0.00
0.39 0.37 0.28 0.20 0.13 0.08 0.05 0.03 0.01 0.00
0.64 0.60 0.41 0.26 0.16 0.09 0.05 0.03 0.01 0.00
1.00 1.00 0.52 0.29 0.17 0.10 0.05 0.03 0.01 0.00
1.00 1.00 0.58 0.33 0.18 0.10 0.05 0.03 0.01 0.00
NOW my problem is that I need to plot these guys in a 2D space. My instructor has all but forced us to use a TH2D histogram, but mostly because it's the only root structure she knows how to use. I don't really need a histogram. I'm not going to be doing any calculations off the graph. I just need to graph those points on a surface.
The second portion of the project (which I will start once I get the code working well) is to create a field line arrow at each (x,y) in the axis and have the arrow be equal to the size of the field. Of course, we also can't let ROOT do the work so I have to do the calculations myself and force the issue (so if you want to chime in on that, please feel free).
This is what I am trying to do now (maxSize is the number of elements, in my case 10, and potential is the 2d array where the two indices are the x and y coords of the point):
for (int y = 0; y < (2 * maxSize - 1); y++)
...for (int x = 0; x < (2 * maxSize - 1); x++)
...potent->SetBinContent(x + 1, y + 1, potential[abs((maxSize - 1) - x)][abs((maxSize - 1) - y)]);
What I'm getting is not what I want. I've attached an image (
My instructor is not as helpful as I would like and I am forced to be teaching myself root. I can give any other info/code you need and I could REALLY use some help. This seems like it should be so easy, and it is turning out to be anything but.
Oh, and I will be the first to admit that I really have a very poor understanding (if at all) of what a bin is and am fairly certain it isn't quite what I think it is.
Thanks.
Last edited: