I am trying to plot a potential diagram for two charge plates. I have a code which does that in python. I am now trying to convert that code block into julia. But I am unable to do so. Can someone help?
The code in python :
You have created a grid, grids, but here you replace that grid with grids = 1 .- (zv /100), so the 3D grid is now gone. The actual error then is triggered on the next line, since Julia Arrays have one-based indexing, but you are giving it 0, which is a BoundsError.
I’m not sure exactly what you would like to do, but if you are looking to plot a slice of the original grid, maybe first remove the redefinition of grids, and then try
BTW, there are two issues with this line. Firstly, it allocates a Vector, probably needlessly. You can in most cases just use 1:N instead of collect(1:N). It’s faster and better. Secondly, you are making xv, yv, and zv all point to the exact same vector, which means that if you modify one of them, all three are affected.
My general advice is ‘never use collect’. Only use it if your code cannot work without it.
One more thing. I’m not exactly sure why you are moving code from numpy to Julia, but if it is for performance reasons, you should be aware that writing Julia in ‘numpy-style’ is not likely to speed it up. In fact, the Julia version will probably be slower, since Julia slices create copies.
If you want fast code, you should read the performance tips in the manual.