This page is still largely in progress.
We are now going to start looking at differential calculus in higher dimensions. Before we look at equations, in which case we tackle the general problem of partial differential equations, we consider derivatives of fields, either scalar or vector. A scalar can be regarded as a 1D vector so this lecture is about differential calculus of vector fields. We will focus on 2D fields for ease of visualisation but the principle would apply similarly to higher dimensions.
The main differential operators of vector calculus are:
for a scalar f(x,y) and vector \vec F(x,y) fields, respectively. The vectorf field consists itself of two scalar fields F_x and F_y:
\vec F(x,y)\equiv F_x(x,y)\hat\imath+F_y(x,y)\hat\jmath
We can now remind the definitions and physical meaning of the differential operators (remember, in 2D):
Derive the above results from a literal understanding of \nabla as the vector \begin{pmatrix}\partial_x\\\partial_y\end{pmatrix} and check the character of the resulting object in each case (scalar or vector).
... definition of grid ...
Starting with the gradient:
To fix idea, we will define a function that looks like a mountain landscape, as follows:
function f(x,y) (cos(x*y)*y*((x-0.5)^2+(y-0.15)))^2*exp(-x^2-y^2/2) end
which, from Lecture 8, we can represent as a 3D landscape:
wireframe(x,y,f, xlabel="x", ylabel="y", zlabel="Mountains", dpi=200)
This is a 3D plot so it requires some mental flexibility to capture in its full complexity, in which case one can use an animation over the camera angle. There is a bug restricting the camera angle between 0 and 90°, so to make a seamless animation, we can loop back and forth using the vcat command:
julia> for i ∈ vcat(0:5:90, 85:-5:5) display(wireframe(x,y,f, xlabel="x", ylabel="y", zlabel="Mountains", camera=(i,20), dpi=200)) # print("$(i) ") sleep(0.1) end
Beyond the 3D plot in relief and with perspective, we are often interested in a more accurate and quantitative picture, in which case we would use a density plot of our scalar field (sf), which we first discretize as this will be needed for our calculations anyway:
lx=-4:.01:4; ly=-4:.01:4; sf=[f(x,y) for y=lx, x=lx];
and then plot:
default(; xlabel="x", ylabel="y") heatmap(lx, lx, sf)
or only the isolines, which give us a familiar topographic feel of the scalar field:
contour(lx, lx, sf)
function Dx(myvec) (myvec[3]-myvec[1])/2 end
vfx=[Dx(sf[iy, ix-1:ix+1]) for iy ∈ 2:size(sf)[1]-1, ix ∈ 2:size(sf)[2]-1]
heatmap(slx, slx, ssf) contour!(slx, slx, abs.(vfy), fill=false, lc=:white, lw=.1)
heatmap(slx, slx, ssf) contour!(slx, slx, abs.(vfy), fill=false, lc=:white, lw=.1)
Modulus square:
heatmap(slx, slx, sqrt.(vfx.^2+vfy.^2))
The link between the discretized grid index k and the continuous line x is:
\begin{align} x&=k\delta x-4\\ k&={x+4\over\delta_x} \end{align}
so let us say we'd like to know the distanced climbed up from the center of the "map" to the mountain heading north. This is the profile, obtained as a vertical "cut" through the mountain landscape:
plot!(slx, ssf[:,400])
This is obtained as the sum over the little increases:
julia> sum(vfy[:,400][400:(round(Int,((2+4)/δx)))])*δx 2.3866293729048347
and should correspond to the elevation of the mountain at the final point (we started from 0):
julia> f(0,2) 2.3873143962938483
There is a numerical error, but the result is fairly accurate. We can in fact reconstruct it for any point of our journey:
plot(0:.01:3.9, [sum(vfy[:,400][400:ceil(Int,(x0+4)/δx)])*δx for x0=0:.01:3.9], xlabel="y", ylabel="h", label="From gradient") plot!(slx, ssf[:,400], la=.25, lw=2, label="Exact", legend=:topleft)
We have headed north but the same would work vertically or along any line, in fact, along any trajectory:
Show numerically on the landscape provided that:
\int_{\vec a}^{\vec b}\nabla f\cdot d\vec r=f(\vec b)-f(\vec a)
We now turn to the divergence and curl, which apply to a vector field. In 2D, both return a scalar field, so they are pretty similar:
Now for the Laplacian, this one is interesting because it mixes the
We check that the following are harmonic functions:
we now turn to a different, matrix-form approach to the problem:
[show] Table of Contents Crash Course on Scientific Computing
|
---|