Based on your clarifications starting here, I see that you are starting with the simple case in which $n(r^\prime) = 1$. In this case we have the integral:
$$\tag{1}
\int \frac{1}{|r-r^\prime|}\textrm{d}r^\prime,
$$
for which can check to see whether or not our numerical integration procedure works by comparing with the analytic expression for the integral:
To do the integral in Eq. 1 numerically, we need to know how to numerically integrate a function of two variables, $r$ and $r^\prime$, with respect to one of them $r^\prime$. This search for "numerical integration of two variable function with respect to one variable" results in many immediate results, including (in order) on the following high-quality Q/A venues:
- Matlab Answers: "Integration of function with two variables with respect to one of them"
- How to implement the trapezoid rule in MATLAB is the same as what you would want to do in NumPy.
- Mathematica StackExchange: "Numerical integration of two variable function"
- Although I admit that Mathematica's
NIntegrate
function mentioned in the accepted answer, shelters you from getting to see the details, but the details for how to do it in MATLAB are indeed given in the question).
- StackOverflow: "numerical integration of two variable function over one variable only in C++ (using Numerical Recipes libraries)"
- ResearchGate: "What are the methods for the numerical integration of a function of more than one variable?
Basically what you are hoping to do is perfectly reasonable and has been implemented in many places, many times. You are on the right track, but as for your question:
"but won't the denominator just be zero?"
you may just have allowed $r = r^\prime$ at some point, which would have lead you to receive an error suggesting that your denominator is zero.
If you look at the analytic expression for the integral, in my above screenshot, you'll see that even the analytic expression becomes ugly when $r=r^\prime$, particularly because you'd be evaluating $\log(0)$.
Notice also that the analytic expression (in the above screenshot) for the integral, looks remarkably similar to what you would get if you calculate the integral of a related 1-variable function:
\begin{align}\tag{2}
u &= r - r^\prime \\
\textrm{d}u &= -\textrm{d}r^\prime\\
-\int &\frac{1}{|u|}\textrm{d}u.
\end{align}
However, while this last piece of information may be helpful in the early stages of your code development, in which you want to test your code for simple functions like $n(r^\prime)$ = 1, the more general numerical techniques for calculating the integral of a 2-variable function with respect to one of the variables, may be the best way forward for the general case.