I have a set of N macroscopic particles, each representing a group of electrons. Each of these macroscopic particles has a different charge.

My system is one-dimensional so all particle´s positions are described by their position along the z-axis. I have an array positionsof length N, where each element represents the z position of a single particle. positions[i] represents the position of the i$^{th}$ particle.

These values for the positions are such that the carge density is uniform along z between $0$ and $L$. $$\rho_1(z) = N_1$$

I need to disturb my charge distribution by a factor: $$\delta \rho = A \cos \left( \frac{\pi mz}{L} \right)$$ In order to have a final charge distribution of: $$\rho_2(z) = N_1 + A \cos \left( \frac{\pi mz}{L} \right)$$ with $m$ an integer equal or larger to 1 in order to keep charge conserved.

I have been struggling with this for longer than I would like to admit, could someone point me into the right direction. How could I modify each positions[i] in order to modify my charge distribution as expected.

Effectively what I need is to remove particles from the region where $\delta \rho < 0$ and add them in regions where $\delta \rho > 0$ but following the cosine density I need.


1 Answer 1


I am assuming that you want to keep the total charge constant. Let's assume that your array is of size $2m$. Then you can update the first $m$ entries of the array using the assignment $r[i] \leftarrow r[i] + A\cos(\pi i/m)$ and the last $m$ entries using the assignment $r[i] \leftarrow r[i] - A\cos(\pi i/m)$. I suggest that you modify each half separately to ensure that the total charge indeed remains constant.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.