Now -- our last question:
Suppose I'm given two functions f1(x,y) and f2(x,y). Is there a vector field F(x,y) with div(F(x,y)) = f1(x,y) and curl(F(x,y)) = f2(x,y)? If so, Is there a formula for finding P(x,y) and Q(x,y) given the divergence and curl?
The answer is yes, and the same vector field G that we ran into in the proof of the mean value theorem provides the way.
To facillitate our analysis, we first introduce a "regularized" version which is defined everywhere. Recall that G was the gradient of
g(x,y) = (1/2)*ln((x-x0)2 + (y-y0)2)
Fix a small number h > 0 , and define
gh(x,y) = (1/2)*ln((x-x0)2 + (y-y0)2 + h2)
Then the argument of the natural logarithm is strictly positive for all (x,y), and hence gh(x,y) is defined everywhere.
Let Gh denote its gradient, which is also defined everywhere. Computing it we find:
Gh(x,y) = ((x-x0)2 + (y-y0)2 + h2)-1* (x-x0,y-y0)
Now, computing the divergence of this we find:
div(Gh(x,y)) = 2*h2/ ((x-x0)2 + (y-y0)2+h2)2
This can be rewritten in an illuminating form:
Define j(x,y) = 2/(x2 + y2 + 1)
Then
div(Gh(x,y)) = h-2j((x-x0)/h,(y-y0)/h)
The factors of h are aranged in this just right so that something interseting happens:
We claim that the following is true: For any continuous function f(x,y), and any point (x0,y0),

To see why this is true, look at the following picture:

When h is very small, the graph of h-2j(x/h,y/h) is very sharply peaked around the origin. The peaking gets sharper and sharper as hdecreases. So for small h, f(x0-x,y0-y) is practically constant where h-2j(x/h,y/h) "lives", and that constant is f(x0,y0).
If we treat f(x0-x,y0-y) as being exactly constant where h-2j(x/h,y/h) "lives", we can take it outside the integral sign, and all we have to do is the integral of h-2j(x/h,y/h) over the whole plane.
The limiting value will then be f(x0,y0), the constant we took out, times the value of the integral left behind. So everything is alright if the value of the integral is 2*pi.
To see that this is the case, introduce new variables
u = x/h and v = y/h
then h-2dxdx = dudv and we have that the integral of h-2j(x/h,y/h) over the whole plane is

Putting it all together, we get just what we claimed.
Now here is a more formal proof, that doesn't rely on the picture -- though you should try to understand why it works using the picture!

The formal proof is really just the same thing. The only thing you might worry about is why we could take the limit under the integral sign. But that would be analysis, not calculus! So we won't worry.
Now, given any continuous function f(x,y), and any point (x0,y0), we define the vector

Actually, since (x0,y0) is arbitrary, we can let it vary over the plane. Thinking of x0 and y0 as variables, we can take the divergence of it (in these variables) To do this, switch the order of integration and taking the divergence. That's O.K. because the divergence is acting on the variables x0 and y0, while the integration is in the variables x and y. Also
div(-Gh(x - x0,y - y0) = h-2j((x-x0)/h,(y-y0)/h)
when we take the divergence in the variables x0 and y0, since they come in with opposite signs from x and y. Thus moving the divergence under the integral sign puts a factor of h-2j((x-x0)/h,(y-y0)/h) there where -Gh(x - x0,y - y0 was.
Then since

as one sees by making the substitution
u = (x - x0)/h and v = (y - y0)/h.
Hence our above results about the h tending to zero limit imply:
This is just what we want! We started with f(x,y) and built a vector field out of it, whose divergence, in the limit in which h tends to zero, is just f(x,y) evaluated at the point in question.
Better yet, as indicated in the last line of equations, the curl is zero. So we have constructed a "curl free" vector field whose divergence is the given function f(x,y), at least in the limit.
So let us take the h goes to zero limit in the definition of Fh and define:

The notation certainly isn't ideal -- Fh does not mean Fh with h = 1! It is more like h = 0. So why not use zero as the subscript?
Well, we'd have used it up when we got to the curl, which comes next. Let us use the notation

and reacll the relation between the divergence, the curl and the perping operation. Because of this, we can immediately take care of the curl by "perping" what we did for the divergence. Define

Then the same analysis shows that curl(F2)(x,y) = f2(x,y) and div(F2)(x,y) =0
We have now proved the following theorem:
Let
f1(x,y) = div(F)(x,y) and
f2(x,y) = curl(F)(x,y).
Define the vector fields F1(x,y) and F2(x,y) in terms of
f1(x,y) and f2(x,y) respectively,
as above.
Then
F(x,y) = F1(x,y) +
F2(x,y) everywhere.
Moreover, given any bounded functions f1(x,y) and f2(x,y), define
the vector fields F1(x,y) and F2(x,y) in terms of them as above, and
define F(x,y) = F1(x,y) +
F2(x,y). Then F(x,y)
is a vector field whose divergence is f1(x,y),
and whose curl is f2(x,y).
If F(x,y) tends to zero as
(x,y) tends to infinity, it is the unique such vector field.
This theorem tells us how to find an electric field given the charge
distribution. If we work in units in which the electrostatic
equation reads
div(F(x,y)) = rho(x,y)
Then
Formulae for a Vector Field in terms of its Divergence and Curl
Suppose that F(x,y) is a vector field such that
div(F)(x,y) and curl(F)(x,y)
are bounded, and such that F(x,y) tends to zero as
(x,y) tends to infinity.
