So a mathematical concept that is very important in physics, especially, for example, in electrodynamics,
is multi-dimensional derivatives.
So this includes the so-called Nublar operator, which contains the partial derivatives with respect
to the individual coordinates.
So with the help of this novel operator, we can calculate the gradient and the curl and the divergence,
and we can calculate those things for multidimensional functions.
So this means, for example, that a function is itself still single valued.
So it's not a vector, but just a scalar function.
But it depends on multiple arguments.
For example, X, Y and Z.
Or it could also mean that the function has multiple dimensions itself, so it has an X, Y and Z component,
and all of them depend on X, Y and Z themselves.
So now we can use to novel operator to basically calculate what happens when we apply this to a scalar
function.
You see this the gradient where we apply the partial derivatives now to the function for each of these
components.
For the curl, we calculate the cross product and for the divergence we calculate the dot product of
the novel operator with the function.
So for example, here we see the typical cross product shape y z minus z y z x minus XY and x y minus
y x.
So you just have to consider these partial derivatives, even though they are just operators, just
like you would consider a number of variables.
And then you just let them act on the function.
So we we don't want to really deal so much here with the mathematics, but we will just implemented
and we will consider a few examples.
So as the functions that we are using here, we have these examples.
The first one is an exponential function, basically a Gaussian function, which is a bit modulated
in the white direction.
And I have programmed this already.
I have written down F of R R as a vector that has X, Y and Z.
So three components, it is basically an exponential function and then X component square and here y
component for the total power of for.
And then I have used the plot prediction command to plot this, and you see it looks a bit like a mountain.
This is really the physical example that we will consider here.
Let's consider a mountain that looks like this.
We have the X and Y coordinate and the values to Z coordinate.
And then the question is what is the gradient at?
The gradient always tells us the direction of the steepest slope of the mountain.
So when we are at some point and we calculate the gradient, it will always point in to the direction
where the slope is the steepest.
And so the other example of a vector valued function is Geof River G is a vector and it is Vector R,
so basically a vector with X, Y and Z as two components divided by the absolute value of art.
So square root of x squared plus y squared plus c square.
This looks very simple, but actually to calculate the divergence and the curl of this is not so easy
to do analytically.
But here we will do that just numerically, and we will implement these functions here.
And in terms of physics, this expression is very relevant, for example, in electoral dynamics.
And there we even have to calculate the curl and the divergence of this term to determine, for example,
the electric field of some charged distribution or vice versa.
So now let me show you what this function looks like.
Vector are divided by arm.
So you see if you're interested, how to do this and please just post a video.
I have used here a quiver plot, but actually it's not so important right now.
I will use this later on to calls several times, and there I will explain to you in detail how this
works.
Basically, you just provide X, Y and Z coordinates by using a mesh grid command and then you provide
the values of the function.
Also, X, Y and Z components, another will show you the direction of G at every point in space.
And you see, since it is vector are divided by R, it always points along the radial director.
All right.
So the next thing that we will implement is we will implement the gradient, so the gradient of.
So this means, as I told you, the direction of the steepest slope of this mountain here.
So let's go ahead and do this.
So the gradient is defined.
And it is the fight for function, if it is to find for position arc, which is a vector of three components
and it is defined with a step size because it is still a derivative, after all.
So we need the step size.
And here, just for simplicity, I will use the central difference as method.
You could also apply any other method that we have encountered previously.
It will just increase or decrease the accuracy of the method.
But here central differences will do.
It's just just an exercise to show you how it works.
So just to make our lives a bit more easy, we can define something like this where the individual components
of arm are labeled X, Y and Z, and then we can write partial x has given as.
But now we must use central differences with respect to the variable of X.
So this would be f off.
Now we must apply the array to vector array.
X, Y and Z.
And as I told you, central differences, we will change X by the value of H, and then we will just
subtract the value of the function where H is reduced from X and we divide by two.
H, this is really exactly as we did before, but we need to be careful now that we used to correct
argument here.
Then when you remember how the gradient was defined, we do know the same thing for the other components.
But we we calculate the derivative respect to Y and with respect to see.
So we will just write basically the same thing again, partial y and there the age will be added to
Y and subtracted from Y and for Z, the same thing with the C component.
And then the last thing is we must, of course, return something, and this will be a because now it's
the vector gradient is always a vector because it shows you an orientation of the steep slope, so it
must be a vector.
And those will be partial acts, comma, partial light and partial z.
And then we can just give us some random reference point.
For example, are is given as an P dot array
0.5 minus one point two.
And you see, our function doesn't even depend on C, so it can take it and evaluate just to zero.
But I could also take minus eight.
Doesn't matter.
And then we must specify the step size, which of course, gives us a better result the smaller it is.
So I take it quite small and then I call gradient of f petition are steps each, and the value is now
something like this.
So you see we are to position 0.5 and minus one point two.
And the direction of the gradient is a bit in the negative x direction and along the positive y direction.
So let's look at the figure we go to 0.5 and minus one point two.
So, for example, 0.5 minus one point two is something like here.
So the gradient would point a bit to the left.
Negative x direction and strongly along.
Y yeah, positive y direction.
Let's see if this is correct.
Yes, this is exactly what we have calculated, and even we can check this with the analytical solution.
Because if you know a bit about the mathematics and the derivatives, it's pretty easy to calculate
the gradient.
You just have the outer derivative with it, which is the exponential function of minus x squared minus
Y to the power of four.
And then you multiply the derivative, which for the X component will be minus two x and for the Y component
will be minus four times Y two to pull off three.
So this is exactly what I've written down here and now I can just copy what I have prepared.
This is just an array which basically includes these exact components that I have just written down,
and the value is exactly what we have here.
And so you see within it with the step size of zero point zero zero zero one, we get really exactly
the same result as we should get from analytics.
So in this case, especially the central differences method was totally sufficient and we get a nice
result for the gradient.