  We describe a quantum algorithm for preparing states that encode solutions of
non-homogeneous linear partial differential equations. The algorithm is a
continuous-variable version of matrix inversion: it efficiently inverts
differential operators that are polynomials in the variables and their partial
derivatives. The output is a quantum state whose wavefunction is proportional
to a specific solution of the non-homogeneous differential equation, which can
be measured to reveal features of the solution. The algorithm consists of three
stages: preparing fixed resource states in ancillary systems, performing
Hamiltonian simulation, and measuring the ancilla systems. The algorithm can be
carried out using standard methods for gate decompositions, but we improve this
in two ways. First, we show that for a wide class of differential operators, it
is possible to derive exact decompositions for the gates employed in
Hamiltonian simulation. This avoids the need for costly commutator
approximations, reducing gate counts by orders of magnitude. Additionally, we
employ methods from machine learning to find explicit circuits that prepare the
required resource states. We conclude by studying an example application of the
algorithm: solving Poisson's equation in electrostatics.
