# A source from an array The potential of a dozen charges that are given as an array of numbers, not as a formula. ```python import numpy as np import sympy as sp import pdemagic as pm x, y = sp.symbols("x y", real=True) phi = sp.Function("phi")(x, y) rho = sp.Function("rho")(x, y) axis = np.linspace(-4, 4, 129) gx, gy = np.meshgrid(axis, axis, indexing="ij") measured = np.zeros_like(gx) places = np.random.default_rng(1).uniform(-2.5, 2.5, (12, 2)) for number, (cx, cy) in enumerate(places): measured += (-1) ** number * np.exp(-6 * ((gx - cx) ** 2 + (gy - cy) ** 2)) scattered = pm.Problem( sp.Eq(pm.laplacian(phi), -rho), domain=pm.FreeSpace(x, y), data={rho: pm.GridData.from_axes(measured, axis, axis)}, ) axes = pm.solve(scattered).plot() axes.contour(axis, axis, abs(measured).T, levels=[0.5], colors="gray", linewidths=0.8) ``` ## What it shows Poisson's equation with a charge density that comes as numbers on a grid, as from a measurement or from another program. In the equation the density is an undefined function, `rho`, like the unknown, and `data=` hands its values to the problem. Here the array holds six positive and six negative charges at places drawn at random. The colours are their potential, and the grey lines mark where the array is largest in magnitude. Where two charges of opposite sign fall close together, they cancel in part. ## What pdemagic decided The equation is Poisson's in free space, and the method is the Fourier method (`fourier`), as for a formula. The planner chose no grid: the solution lives on the grid of the data, 129 by 129 points. Whatever lies outside the array counts as zero charge. ## More - [Data from arrays](../topics/data.md) - [Use measured data as a source](../howto/use-measured-data-as-a-source.md) - [Poisson's equation by Fourier convolution](../methods/fourier-poisson.md) - [Data and bodies in the reference](../ref/data-and-bodies.md)