Understanding Gradient and Divergence

Embed Size (px)

Citation preview

  • 8/8/2019 Understanding Gradient and Divergence

    1/24

    UNDERSTANDING GRADIENT

    The gradient is a fancy word for derivative, or the rate of change of a function. Its a vector (a direction to

    move) that

    y Points in the direction of greatest increase of a functiony Is zero at a local maximum or local minimum (because there is no single direction of increase)

    The term gradient (grad) typically refers to the derivative ofvector functions, or functions of more than

    one variable. Yes, you can say a line has a gradient (its slope), but using the term gradient for single-

    variable functions is unnecessarily confusing. Keep it simple.

    Gradient can refer to gradual changes of color, but well stick to the math definition if thats ok with you.

    Youll see the meanings are related.

    Properties of the Gradient

    Now that we know the gradient is the derivative of a multi-variable function, lets derive some properties.

    The regular, plain-old derivative gives us the rate of change of a single variable, usually x. For example,

    dF/dx tells us how much the function F changes for a change in x. But if a function takes multiple variables,

    such as x and y, it will have multiple derivatives: the value of the function will change when we wiggle x

    (dF/dx) and when we wiggle y (dF/dy).

    We can represent these multiple rates of change in a vector, with one component for each derivative. Thus,

    a function that takes 3 variables will have a gradient with 3 components:

    has one variable and a single derivative:

    has three variables and three derivatives:

    The gradient of a multi-variable function has a component for each direction.

    And just like the regular derivative, the gradient points in the direction of greatest increase (trust me on

    this, Ill create a derivation a bit later ). However, now that we have multiple directions to consider (x,

    y and z), the direction of greatest increase is no longer simply forward or backward along the x-axis, like

    it is with functions of a single variable.

    If we have two variables, then our 2-component gradient can specify any direction on a plane. Likewise,

    with 3 variables, the gradient can specify and direction in 3D space to move to increase our function.

    A Twisted Example

    Im a big fan of examples to help solidify an explanation. Suppose we have a magical oven, with coordinates

    written on it and a special display screen:

  • 8/8/2019 Understanding Gradient and Divergence

    2/24

    We can type any 3 coordinates (like 3,5,2) and the display shows us the gradient of the temperature at

    that point.

    The microwave also comes with a convenient clock. Unfortunately, the clock comes at a price the

    temperature inside the microwave varies drastically from location to location. But this was well worth it: we

    really wanted that clock.

    With me so far? We type in any coordinate, and the microwave spits out the gradient at that location.

    Be careful not to confuse the coordinates and the gradient. The coordinates are the current location,

    measured on the x-y-z axis. The gradient is a direction to movefrom our current location, such as move

    up, down, left or right.

    Now suppose we are in need of psychiatric help and put the Pillsbury Dough Boy inside the oven because we

    think he would taste good. Hes made of cookie dough, right? We place him in a random location inside the

    oven, and our goal is to cook him as fast as possible. The gradient can help!

    The gradient at any location points in the direction ofgreatest increase of a function. In this case, our

    function measures temperature. So, the gradient tells us which direction to move the doughboy to get him

    to a location with a higher temperature, to cook him even faster. Remember that the gradient does not give

    us the coordinates of where to go; it gives us the direction to move to increase our temperature.

    Thus, we would start at a random point like (3,5,2) and check the gradient. In this case, the gradient there

    is (3,4,5). Now, we wouldnt actually move an entire 3 units to the right, 4 units back, and 5 units up. The

    gradient is just a direction, so wed follow this trajectory for a tiny bit, and then check the gradient

    again.

    We get to a new point, pretty close to our original, which has its own gradient. This new gradient is the newbest direction to follow. Wed keep repeating this process: move a bit in the gradient direction, check the

    gradient, and move a bit in the new gradient direction. Every time we nudged along and follow the gradient,

    wed get to a warmer and warmer location.

    Eventually, wed get to the hottest part of the oven and thats where wed stay, about to enjoy our fresh

    cookies.

    Dont eat that cookie!

    But before you eat those cookies, lets make some observations about the gradient. Thats more fun, right?

    First, when we reach the hottest point in the oven, what is the gradient there?

    Zero. Nada. Zilch. Why? Well, once you are at the maximum location, there is no direction of greatest

    increase. Any direction you follow will lead to a decrease in temperature. Its like being at the top of a

    mountain: any direction you move is downhill. A zero gradient tells you to stay put you are at the max of

    the function, and cant do better.

  • 8/8/2019 Understanding Gradient and Divergence

    3/24

    But what if there are two nearby maximums, like two mountains next to each other? You could be at the top

    of one mountain, but have a bigger peak next to you. In order to get to the highest point, you have to go

    downhill first.

    Ah, now we are venturing into the not-so-pretty underbelly of the gradient. Finding the maximum in regular

    (single variable) functions means we find all the places where the derivative is zero: there is no direction of

    greatest increase. If you recall, the regular derivative will point to local minimums and maximums, and theabsolute max/min must be tested from these candidate locations.

    The same principle applies to the gradient, a generalization of the derivative. You must find multiple

    locations where the gradient is zero youll have to test these points to see which one is the global

    maximum. Again, the top of each hill has a zero gradient you need to compare the height at each to see

    which one is higher. Now that we have cleared that up, go enjoy your cookie.

    Mathematics

    We know the definition of the gradient: a derivative for each variable of a function. The gradient symbol is

    usually an upside-down delta, and called del (this makes a bit of sense delta indicates change in one

    variable, and the gradient is the change in for all variables). Taking our group of 3 derivatives above

    Notice how the x-component of the gradient is the partial derivative with respect to x (similar for y and z).

    For a one variable function, there is no y-component at all, so the gradient reduces to the derivative.

    Also, notice how the gradient can itself be a function!

    If we want to find the direction to move to increase our function the fastest, we plug in our current

    coordinates (such as 3,4,5) into the equation and get:

    So, this new vector (1, 8, 75) would be the direction wed move in to increase the value of our function. In

    this case, our x-component doesnt add much to the value of the function: the partial derivative is always 1.

    Obvious applications of the gradient are finding the max/min of multivariable functions. Another less obvious

    but related application is finding the maximum of a constrained function: a function whose x and y values

    have to lie in a certain domain, i.e. find the maximum of all points constrained to lie along a circle. Solving

    this calls for my boy Lagrange, but all in due time, all in due time: enjoy the gradient for now.

    The key insight is to recognize the gradient as the generalization of the derivative. The gradient points to

    the maximum of the function; follow the gradient, and you will reach the local maximum.

  • 8/8/2019 Understanding Gradient and Divergence

    4/24

    73 Comments

    1. i like it well explained.

    me February 22, 2007 @ 10:43 am

    2. Super!!!

    Jane March 2, 2007 @ 10:00 am

    3. You are the man! Nice work!

    Chris March 21, 2007 @ 8:01 pm

    4. Thanks, glad it was helpful for you.

    Kalid April 1, 2007 @ 1:07 pm

    5. i was always looking for conceptual and practical examples and yes i finally got.

    gaurav June 9, 2007 @ 2:18 am

    6. Awsome!

    Harry June 10, 2007 @ 4:04 pm

    7. well you made a good explanation, that even a not-so-smart guy gets it, but i think you missed theobvious -> WHY does gradient show the direction of the greatest increase.

    I think that the principle of the gradient is quite easy, but understanding why does it work the way

    it does is a bit tricky and you should have focued on it more.

    It would be interesting if you would somehow add it to this good article.

    Inspiration http://mathforum.org/library/drmath/view/68326.html

    good luck !

    Palo August 15, 2007 @ 5:05 pm

    8. Hi Palo, thats a great point! Ive been feeling a bit guilty, if you can imagine it, because Ive lackedthat explanation

  • 8/8/2019 Understanding Gradient and Divergence

    5/24

    Im probably going to do a separate article on the reason *why* the gradient points in the direction

    of greatest increase I have another explanation that it works well with. Thanks for the link and

    feedback!

    Kalid August 15, 2007 @ 5:51 pm

    9. Your introduction is not quite correct:

    You claim: Points in the direction of greatest increase of a function.

    Why? It can also point in the direction of greatest decrease of a function.

    A gradient is one or more directional derivatives. These derivatives are considered in a particular

    direction. In the case of single variable calculus, we generally talk about a directional derivative

    when we consider multiples of the x unit vector, i.e. k*(1,0). To consider the y unit vector, we deal

    with the partial derivatives with respect to y in a given direction. In three dimensions, the 3 partial

    derivatives form what we now call a gradient.

    So in fact it is incorrect to call this a slope or anything else except to say that it describes the partial

    derivatives of a point in the direction of a given vector in space.

    Does this make sense? Please visit my blog for some more interesting reading.

    http://mathphile.blogspot.com/

    John Gabriel September 16, 2007 @ 6:47 am

    10. Hi John, thanks for writing. Youre right, the formal definition of a gradient is a set of directionalderivatives.

    But when thinking about the intuitive meaning, I think its ok to consider the gradient as a vector

    that points in the direction of greatest increase (i.e. if you follow that direction your function will

    tend towards a local maximum).

    Unless Im mistaken, the gradient vector always points in the direction of greatest increase

    (greatest decrease would be in the opposite direction).

    Kalid September 19, 2007 @ 11:49 am

    11. What I was saying is that it points either one way or the other, it is not restricted to the direction ofgreatest increase. As a simple example, consider what happens when you differentiate a parabola:

    You set the derivative equal to 0 and then you determine that it has either a maximum or a

    minimum at its turning point. It is not always a maximum just as it is not always a minimum. Think

    I have explained this correctly now.

    John Gabriel September 27, 2007 @ 7:21 pm

    12. good john you have done a great job.

  • 8/8/2019 Understanding Gradient and Divergence

    6/24

    sqib October 5, 2007 @ 3:41 pm

    13. Hi John, thanks for the clarification. Id still politely disagree and say that in general, the gradientpoints in the direction of greatest increase .

    In the case of 2 dimensions, the gradient/slope only gives a forward or backward direction. A

    positive slope means travel forward and a negative slope means travel backwards.

    Consider f(x) = x^2, a regular parobola. The gradient is zero at the minimum (x=0), and there is

    no *single* direction to go. At x = -1, the slope is negative, which means travel backwards (to x

    = -2) to increase your value. Similarly, at x = 1, you travel forward (to x = 2) to increase your

    value.

    But, as you mention, strange things can happen when the derivative = 0. It can mean you are at a

    local maximum (no way to improve), or at a local minimum (no single direction to improve your

    position forward or back will help). I consider the corner case of zero an exception to the general

    rule / intuition that the gradient is the direction to follow if you want to improve your function.

    Kalid October 5, 2007 @ 10:23 pm

    14. Wonderful explanation!

    Vidhya October 10, 2007 @ 9:09 am

    15. Thanks Vidhya, glad you liked it.

    Kalid October 10, 2007 @ 10:17 am

    16. hi john keep it up you done a great job

    bihazo October 21, 2007 @ 6:21 am

    17. Thanks a bunch! I didnt think it could be this simple to find the maximum increase at a point, so Ithought Id look it up. Thanks to your great explaination, it turn out it was as easy as it seemed it

    should be. Great job! Thanks!

    Travis

    Travis December 2, 2007 @ 5:53 pm

    18. Awesome, glad it worked for you

    Kalid December 2, 2007 @ 7:27 pm

  • 8/8/2019 Understanding Gradient and Divergence

    7/24

    19. thanks!!!!

    caitlyn December 5, 2007 @ 11:09 pm

    20. Hi Caitlyn, youre welcome.

    Kalid December 6, 2007 @ 1:03 am

    21. Thanks! The sadistic microwave example helped a lot.

    Derek December 10, 2007 @ 12:27 pm

    22. Awesome, glad it was useful .

    Kalid December 10, 2007 @ 4:54 pm

    23. Hello Kalid,Did not read your reply for some

    time. Am sorry you do not agree.

    Let me give you an example:

    Suppose we are dealing with pressure

    and height in a certain cubic

    area. Suppose that the middle of the

    cube height is 0 meters. Also suppose

    that we have a whirlpool generated in the

    cube such that the pressure rate increases

    as we go below the middle of the cube.

    Anything below is negative height and anything above

    is positive height. Now, as one rises

    higher in the cube, the pressure decreases.

    If we find the gradient, then according to

    your definition (and many others), then

    the gradient vector for the rate of greatest

    increase will point below the middle of the

    cube, not above. But above the middle we

    find the greatest decrease in rate of pressure.

    In this example, greatest increase points

    downwards and greatest decrease upwards.

    It would probably be better to define

    gradient as a vector that points in a

    direction of greatest increase or decrease.

    Its additive inverse will point in the

  • 8/8/2019 Understanding Gradient and Divergence

    8/24

    diretion of greatest decrease or increase

    respectively. For most physical phenomena,

    your definition would generally be true.

    But what happens when you have an anomaly?

    Make sense?

    John Gabriel December 11, 2007 @ 7:32 am

    24. I do not believe I have the best answer to this question but like yourself, I am a believer in trying tofind the best possible explanation. Once again, I like your website. Keep up the good work Kalid!

    John Gabriel December 11, 2007 @ 7:34 am

    25. Okay, I think I have the best answer. If f is a real-valued function, then del(f) or gradient of f pointsto the greatest increase, whereas -del(f) points t0 the greatest decrease.

    For once planet math has some decent information on this since I last checked:

    http://planetmath.org/encyclopedia/Gradient.html

    I do not endorse everything Planet Math publishes but this particular information appears to be

    correct. In any event, it clears up the previous confusion I think.

    John Gabriel January 16, 2008 @ 1:06 pm

    26. Hi John, thanks for the comment! Yes, thats an important distinction to make: the positive gradientis the greatest increase, and the negative gradient is the greatest decrease. Thanks for helping

    clarify .

    Kalid January 16, 2008 @ 7:11 pm

    27. Thank you!

    Jared March 24, 2008 @ 6:42 pm

    28. This actually makes sense to me. Thanks!

    Bigmouth May 24, 2008 @ 6:20 pm

    29.@Jared, Bigmouth: Cool, glad it was helpful!

    Kalid May 24, 2008 @ 8:10 pm

    30. did not grasp the idea

  • 8/8/2019 Understanding Gradient and Divergence

    9/24

    Anonymous June 6, 2008 @ 1:44 pm

    31. Be more specific. The gradient is the direction to move that gives you the biggest increase.

    Kalid June 6, 2008 @ 1:45 pm

    32. It helps me a lot. But I have some doubt still now.Is it the same concept for gradient of each vertexin a triangle mesh?

    Thanks so much.

    Shaheen June 13, 2008 @ 9:21 pm

    33. Kalid

    Thanks for the great explanations! I thought I was math-retarded for some time; however yourwritings actually make sense to me!

    Take care!

    Johnny T

    JohnnyT June 14, 2008 @ 5:15 pm

    34.@Shaheen: Thanks, glad you enjoyed it. Im not sure I understand the question: in a triangle mesh,you could measure the gradient at each vertex to find the best direction to move. Again, not sure

    if this is your question.

    @Johnny T: Thank you for the comment! Yes, when a subject seems difficult (as vector calculus was

    for me) sometimes its just because the explanation wasnt clicking properly. Thanks for dropping

    by.

    Kalid June 14, 2008 @ 6:39 pm

    35. well done,excellent explaination with solid examples

    wali khan July 3, 2008 @ 4:40 am

    36. Thanks Wali, glad you enjoyed it.

    Kalid July 3, 2008 @ 8:30 pm

    37. thanksbut i have some doubts.how the differentaion gives the maximum space rate of change. as per my

  • 8/8/2019 Understanding Gradient and Divergence

    10/24

    understandings differentiation only is difference between two point in the region say p1 and p2.can

    u clarify

    j.sathish kumar September 17, 2008 @ 3:11 am

    38. Thanks a lot for explaining the concept.leon October 3, 2008 @ 10:05 pm

    39. i was having so much trouble understanding this and now its all clear thank you so much!

    sophie November 4, 2008 @ 2:08 pm

    40.@lon, sophie: Thanks, glad you enjoyed it!

    Kalid November 4, 2008 @ 3:55 pm

    41. Jesus. This was a lot better explained than in my text book and by my professor. I thought we wereusing the gradient as the normal vector but I really doubted that it could be that.

    Ryan Johnson November 10, 2008 @ 12:33 am

    42.@Ryan: Thanks! I struggled with this concept for a while also.

    Kalid November 10, 2008 @ 1:16 pm

    43. thanks ! this explanation made me clear how to find the direction of smallest change.It is just the90 degree rotation of gradiant(the direction of largest change).

    RanjeetKumar January 15, 2009 @ 11:07 am

    44. Thanks very much for your effort

    Shakeel Ahmed January 20, 2009 @ 9:19 pm

    45.Um in your microwave example, arent you pushing the doughboy out the back of themicrowave? (Just wanted to understand the concept). I love these essays, btw, keep them coming!

    Bill March 20, 2009 @ 12:09 am

    46. I loved the microwave analogy.also thanks for clarifying the upsidedown delta now everythingmakes more sense

  • 8/8/2019 Understanding Gradient and Divergence

    11/24

    Hehehe March 20, 2009 @ 8:38 am

    47. stil im confused between scalar field and vector field.

    RAHUL April 10, 2009 @ 1:54 am

    48. how can such a mathematical expression denote the max change? pls i didnt understand therelation of this with mathematics. pls reply sir.

    aradhita chattopadhyay July 16, 2009 @ 10:00 pm

    49. thank you soo much!!

    its a big help for our project

    Can we have your number?hehe

    nat2_bam2 August 2, 2009 @ 2:30 am

    50.@Rahul: A scalar field returns a single value (x), but a vector field returns multiple values (x,y,z).Usually the multiple values (x,y,z) are taken as a direction to follow.

    @aradhita: Hi, thats a question I need to get into in a later post.

    @nat2_bam2: Thanks!

    Kalid August 3, 2009 @ 6:29 pm

    51. Hi kalid! i read your explanation. oh this is very helpful! by the way can you give an example onhow to apply this on a situation of the classic mountain and mountain climber problem? hope you

    will reply. thanks again your explanations were clear

    Migs August 22, 2009 @ 10:57 pm

    52.@Migs: Great question. The classic mountain climber problem is when the vector field gives theheight of the mountain (z) at a certain position (x,y), so z = f(x,y).

    The gradient at any position x,y will give you the direction of the _greatest increase_ in z. That is,

    the gradient will point in the most uphill. Following the gradient will give you the shortest path the

    the top of the mountain (technically, the top of the nearest local maximum). How this helps!

    Kalid August 27, 2009 @ 3:32 pm

    53. beautifulwell said

  • 8/8/2019 Understanding Gradient and Divergence

    12/24

    vignesh September 5, 2009 @ 2:30 am

    54. thanks a lot for the wonderful explanation!!!

    akansha September 19, 2009 @ 8:55 am

    55.@akansha: Youre welcome!

    Kalid September 20, 2009 @ 12:19 am

    56. Very nice! Keep up. Thanks a lot

    anonymous October 14, 2009 @ 7:20 pm

    57. Very nice article!!Hope to see how to find the maximum of a constrained function soon!!

    Thanks a lot!!

    Florencia October 23, 2009 @ 9:58 am

    58.@Florencia: Glad you liked it! Thanks for the suggestion.

    Kalid October 23, 2009 @ 12:56 pm

    59. Very good explanation by the way. So if you are on a landscape given by z=cosy-cosx and u wantto get from (0,0,0) to (4pi,0,0) by moving in the direction of the gradient in the positive x-directionhow would u explain that? What would that path look like?

    ab November 4, 2009 @ 8:32 am

    60. Thanks for the great explanation. Another topic that would be very interesting for you to cover isthe Jacobian, which causes pain for many, many students (including myself).

    P-F November 16, 2009 @ 1:40 pm

    61.@P-F: Thanks for the note I think the Jacobian, and linear algebra in general, would be great tocover. Ive forgotten a lot of it and am looking to relearning .

    Kalid November 17, 2009 @ 5:16 pm

    62. Just wondering something. In that case of f(x,y) = X^2 + y^2, a paraboloid how can the gradientby perpendicular to the tangent plane at all point and only have components in x and y

  • 8/8/2019 Understanding Gradient and Divergence

    13/24

    gradF(X,Y) = 2x + 2y

    How can it point in any other direction other than parallel to the xy plane?

    Im lost here.

    Mark Soric December 12, 2009 @ 9:03 am

    63. thank you kalil. wonderful explanation.

    prabu February 16, 2010 @ 2:25 am

    64.@prabu: Glad it helped!

    Kalid February 16, 2010 @ 5:57 pm

    65. It was a great explanation! But I have a specific problem with gradients. Is there any functions thatcant be expressed as gradient of any parameter? What could be the properties of that function?

    Ashraful May 6, 2010 @ 12:19 am

    66. May I could be more specific about my previous problem. If a function is constant in all direction, isit possible to express the function as gradient?

    Ashraful May 6, 2010 @ 12:33 am

    67. Im not sure if I understand the question the gradient of a constant function would be a 0 vector[perhaps technically (0,0)], that is, there is no direction of greatest increase. If it helps, think of the

    gradient in terms of a derivative (the derivative of a constant function is 0).

    Kalid May 8, 2010 @ 10:31 pm

    68. Math professional!

    Kinar August 30, 2010 @ 10:45 am

    69. Thank you for getting to the heart of why del is required and how to intuitively understand it. Its thefirst time I understand it so well despite reading so much about it before!

    Anonymous September 5, 2010 @ 3:42 pm

    70. damn! i got it now

  • 8/8/2019 Understanding Gradient and Divergence

    14/24

    Anonymous September 6, 2010 @ 8:58 pm

    71. math is so beautiful

    Anonymous September 6, 2010 @ 9:01 pm

    UNDERSTANDING DIVERGENCE

    Physical Intuition

    Divergence (div) is flux densitythe amount offlux entering or leaving a point. Think of it as the rate of

    flux expansion (positive divergence) or flux contraction (negative divergence). If you measure flux inbananas (and cmon, who doesnt?), a positive divergence means your location is a source of bananas.

    Youve hit the Donkey Kong jackpot.

    Remember that by convention, flux is positive when it leaves a closed surface. Imagine you were your

    normal self, and could talk to points inside a vector field, asking what they saw:

    y If the point saw flux entering, hed scream that everything was closing in on him. This isa negative divergence, and the point is capturing flux, like water going down a sink.

    y If the point saw flux leaving, hed sniff his armpits and say all flux was existing. This isa positive divergence, and the point is a source of flux, like a hose.

    So, divergence is just the net flux per unit volume, or flux density, just like regular density is mass per

    unit volume (of course, we dont know about negative density).

    The bigger the flux density (positive or negative), the stronger the flux source or sink. A div of zero means

    theres no net flux change in side the region. In plain english:

    Divergence = Flux / Volume

    Math Intuition

    Now that we have an intuitive explanation, how do we turn that sucker into an equation? The usual calculus

    way: take a tiny unit of volume and measure the flux going through it. We need to add up the total flux

    passing through the x, y and z dimensions.

    Imagine a cube at the point we want to measure, with sides of length dx, dy and dz. To get the net flux, we

    see how much the X component of flux changes in the X direction, add that to the Y components change in

    the Y direction, and the Z components change in the Z direction. If there are no changes, then well get 0 +

    0 + 0, which means no net flux.

    If there is some change in the field, we get something like 1 -2 +5 (flux increases in X and Z direction,

    decreases in Y) which gives us the divergence at that point.

  • 8/8/2019 Understanding Gradient and Divergence

    15/24

    In pseudo-math:

    Total flux change = (field change in X direction) + (field change in Y direction) + (field change in Z

    direction)

    Or in more formal math:

    Assuming F1 is the field in the X direction, F2 in the Y and F3 in the Z.

    A few remarks:

    y The symbol for divergence is called del and is an upside down triangle.y Divergence is a single number, like density.y Divergence and flux are closely related if a volume encloses a positive divergence (a source of

    flux), it will have positive flux.

    y Diverge means to move away from, which may help you remember that divergence is the rate offlux expansion (positive div) or contraction (negative div).

    Divergence isnt too bad once you get an intuitive understanding of flux. Its really useful in understanding in

    theorems like Gauss Law.

    16 Comments

    1. i came across a piece of info saying that the equation of conitinuity comes from divergencetheorem(i will give the statement here:for any arbitrary region of volume v coverd by surface area

    s,the flux of the current density over the surface s is equal to the rate at which mass / charge

    leaves the volume v)

    is there a derivation for this? ..or could anyone tell me an intuitve approach..where i can atleast

    visualise what is happening?

    kirtika September 26, 2007 @ 1:33 am

    2. Hi kirtika, Id have to see some more on this, but I think in this context flux of current densitymeans change in current density.

    This statement may be saying the amount of current you see passing through a surface depends on

    the amount of charge leaving the region (a moving charge can induce a magnetic current for

    example). This is a bit tough to visualize, but as the charge moves the flux through the surface will

    change imagine a firehose (constantly spitting out water) moving through an invisible sphere. As

    the hose goes along, the amount of water passing through will change.

    Kalid October 16, 2007 @ 10:52 pm

  • 8/8/2019 Understanding Gradient and Divergence

    16/24

    3. would be nice if you could tell us something about Gauss & Stokes Thm! nice stuff btw!

    kalimentes November 29, 2007 @ 3:20 pm

    4. Thanks I actually have some stuff on Gauss and Stokes at my old site here:

    http://www.cs.princeton.edu/~kazad/resources.htm

    Which I need to revise and update. But its on the list

    Kalid November 29, 2007 @ 4:44 pm

    5. Hiyall!

    I wish to tell you a story.

    As a young kid and in the high school I had few to no problems with math; it was easy to

    understand and the examples in the maths books were quite intuitive and visual.

    What a shock it was to attend the first math courses in the university. I dont know about the ones

    for math majors, but at least the math course materials for us engineering students were conjured

    from some fiery bowels of hell.

    With no clarifying pictures and even less explanations (divergence measures the change of vector

    function in its direction and the spreading of the direction. Now do the exam. is pretty much all we

    get), the typical brute-force technique among tech students here is to memorize the ten or so

    calculations that the exam questions are picked from each year and vomit them on the test paper.

    Formula after formula. Equation, equation, equation.

    Somebody just forgot to tell what the hell these formulas do and what they are used for anyway.

    All this bitter rambling is here for a reason I really wish to thank you for your explanations! This is

    the first time that instead of memorizing some stupid upside down triangles and strange-looking ds

    with no comprehension of them whatsoever I really do understand, what the hell a curl actually is.

    I am going to recommend your site to every tech and math student I know. Something like this is

    really missing from the teaching of mathematics and I dont know whether the professors are too

    jaded, indifferent or too alienized from the real world to notice this.

    In case you havent noticed, there are some neat animations of divergence and curl in

    http://www.math.umn.edu/~nykamp/m2374/readings/divcurl

    also.

    Once again A big great thanks to you, Kalid! Keep up the good work!

    Jaakko Seppl June 2, 2008 @ 11:36 pm

  • 8/8/2019 Understanding Gradient and Divergence

    17/24

    6. Hi Jaakko, thanks for the comment its something I would have written a few years ago! I hadthe same exact problem with regurgitating formulas in engineering classes, which motivated me to

    create this site. It really bothers me to know how without knowing why .

    Thanks for that link, the animations look really cool! Visualizing these concepts makes them somuch clearer.

    Again, appreciate the comment!

    Kalid June 5, 2008 @ 11:11 am

    7. hi nice post indeed. it clarified a lot of stuff regarding divergence. but tell me one small thing.Is it possible when i consider an infinitesimal small volume from the actual volume, and the

    divergence might be flowing out in the infinitesimal volume but in the overall volume the divergence

    might be flowing in towards the volume?

    janakiraman October 8, 2008 @ 10:27 pm

    8. Hi and also it would be extremely good if you can also tell something similar about the Tensors aswell.

    janakiraman October 8, 2008 @ 10:37 pm

    9. i whould like someone to explane me curl what is mean in simple or what is mean in fluid flowsimple example with a culculation number,iam intersted in but i need help ,regardes basheer

    basheer June 15, 2009 @ 4:04 am

    10. Thank you thank you thank you!!

    I never thought understanding the divergence was this easy. I knew that it measured the amount of

    flux entering or leaving, but

    Total flux change = (field change in X direction) + (field change in Y direction) + (field change in Z

    direction)

    really hit the spot! I even understand that enigmatic equation now! I really cant believe why

    nobody teaches these things. (I always assumed that these were so intricate concepts that us lessermortals with small brains couldnt understand them)

    Keep going mate. You are the man.

    This is what I have to say December 27, 2009 @ 5:18 am

  • 8/8/2019 Understanding Gradient and Divergence

    18/24

    11.@This: Thanks, really glad it helped! That equation made things click for me too. Ive come torealize that the vast majority of math ideas are all within our grasp if presented in the right

    light .

    Kalid December 27, 2009 @ 2:02 pm

    12. Very nice site. If I understand you correcly you mean that the div is the flux density.

    You state: So, divergence is just the net flux per unit volume, or flux density, just like regular

    density is mass per unit volume (of course, we dont know about negative density).

    The bigger the flux density (positive or negative), the stronger the flux source or sink. A div of zero

    means theres no net flux change in side the region. In plain english:

    Divergence = Flux / Volume

    In terms of magnetic fields, does this mean that if the magnetic flux density is zero the change in

    magnetic flux is zero inside a volume?

    In case the magnetic flux is larger than zero, does this mean that the change in magnetic flux inside

    a volume is finite (that there is a change of magnetic flux inside that volume). In case where does

    that change in magnetic flux come from?

    MH June 11, 2010 @ 8:50 am

    13. I have read in the litterature that the flux density inside a transformer core material does changecaused by VOLTAGE changes over time, NOT from the magnitude of current: I dont understand

    why. How can voltage changes cause the field lines to change direction inside the magnetic material(or is that wrongly understood). Can someone explain magnetic flux density and possibly relate it to

    flux density as it is explained here.

    MH June 11, 2010 @ 8:56 am

    14. Hi again. Sorry to spam you. Overathttp://www.math.umn.edu/~nykamp/m2374/readings/divsubtle/ they mention that Divergence

    measures expansion or compression of a vector field. We ended that section with the example

    where we immersed a sphere into a vector field that had positive divergence everyone. No matter

    where one moves the sphere (with the sliders), more fluid flows out of the sphere than into the

    sphere, indicating the fluid is expanding.

    Let us say that instead of fluid, we talk about magnetic flux. Does that mean that with a positive

    magnetic flux density (divergence), the flux lines are expanding. Does that mean that the magnetic

    field is changing in strength.

    How can a magnetic field that changes in strength induce a voltage in a wire running thru the

    magnetic field?

  • 8/8/2019 Understanding Gradient and Divergence

    19/24

    MH June 11, 2010 @ 9:03 am

    Gradient and Maximum Increase of a Function

    Date: 07/19/2005 at 04:58:42From: JillSubject: Linear Algebra and Calculus

    I am having difficulty explaining why the gradient points in thedirection of the maximum increase of a function. Several resourcesmake the statement, but no one explains it. It is probably somethingsimple I am overlooking. Can the dot product be used to justify it?

    Thanks.

    Date: 07/19/2005 at 05:54:56From: Doctor Jerry

    Subject: Re: Linear Algebra and Calculus

    Hello Jill,

    One explanantion uses the idea of "directional derivative," whichusually precedes the definition of the gradient.

    If f is a function of two variables, if a = is a point(specified, for convenience, as a position vector) in the domain, andif u = is a unit vector (thought of as being based at a), thenthe directional derivative of f at a and in the direction u is thelimit of the ratio

    [ f(a+h*u) - f(a) ] / h

    as h->0. If this limit exists it is often denoted as D_u f(a), where"_" means subscript. This is the rate of change of f in the directionu. It is easy to see that if u = and , the directionalderivatives are the partials f_x(a) and f_y(a) of f at a,respectively.

    If f is differentiable at a, one can show that

    D_u f(a) = dot u. (dot = dot product of vectors)

    Of course, is the gradient of f at a. Recalling thatthe dot product of two vectors is the product of their lengths and the

    cosine of the angle between them, it follows that the maximumdirectional derivative happens when u is the direction of thegradient, that is, the cosine of the angle between them is 0.

    Please write back if my comments are not clear.

    - Doctor Jerry, The Math Forumhttp://mathforum.org/dr.math/

  • 8/8/2019 Understanding Gradient and Divergence

    20/24

    Date: 07/19/2005 at 11:48:09From: Doctor GeorgeSubject: Re: Linear Algebra and Calculus

    Hi Jill,

    Doctor Jerry gave a very nice answer to your question. Here isanother approach to it.

    Using Doctor Jerry's notation, if we examine the Taylor expansion ofthe function, the linear term is

    h dot u

    For sufficiently small values of "h" the linear term will dominate theexpansion, so the maximum increase in a small neighborhood about "a"will occur when the linear term is maximized. By Doctor Jerry's

    reasoning, this happens when "u" is the direction of the gradient.

    Just to broaden the picture a bit, in optimization theory the goal isoften the minimization of a function. The direction opposite thegradient is called the direction of "steepest descent."

    - Doctor George, The Math Forum

    Partial Derivatives

    Differentiating a function of more than one variable is more complicated than

    differentiating a function of one variable. For a function of several variables the rate

    of change of the function depends on direction!. Consider the function

    which is shown as a surface in xyz space below.

  • 8/8/2019 Understanding Gradient and Divergence

    21/24

    Let us assume that the surface corresponds to a mountain and assume that we are amountain climber located the peak near x=0 and y=0. Note that if we travel in the

    positive x direction, the elevation decreases rapidly. The derivative in the x directionis negative and has a large magnitude. On the other hand, if we travel in the positive y

    direction, the elevation changes slowly. We can travel in any direction, not only

    parallel to the x and y axes, and the derivative depends on the direction.

    Another way to display a function of two variables is by a contour plot. You haveseen contour maps. Points with the same elevation are joined by lines. You have seen

    weather maps where points with equal temperature are joined by lines (these lines are

    called isotherms). A contour plot of the function z=f(x,y) consists of a family ofcurves f(x,y)=c (called level or contour curves) in the xy plane for various values of c.

    On the curve f(x,y)=c, z=c. A contour plot of the model function is shown below:

  • 8/8/2019 Understanding Gradient and Divergence

    22/24

    On each curve in the contour plot z =f(x,y) is constant. On different curves the

    constant is different. We haven't listed the values of z on the various curves above.

    However, by comparing the plot of the surface with the contour plot, we conclude thatthe oval contour near the origin corresponds to a large value of z, for example. Note

    that if one moves in the negative x-direction from the origin, then one crosses a

    number of contour curves in a short distance. This implies a rapid change in functionvalue. If one travels in the y-direction, one does not cross as many contour curves in a

    short distance; the change in the function value is less rapid.

    We are now ready to discuss partial derivatives. Suppose we are interested in

    determining the rate of change of z=f(x,y) for fixed y. For example, let y=0 in our

    model problem. Then

    z is a function of the single variable x. dg/dx can be computed using techniques from

    single variable calculus. g'(x)=4x^3+3x^2-36x-16. In general for arbitrary y, the

    derivative in the x direction is called the partial derivative with respect x and is

    defined by

  • 8/8/2019 Understanding Gradient and Divergence

    23/24

    In the definition y is held fixed. To compute the partial derivative with respect to x we

    differentiate with respect to x and assume y is a constant. For the model problem we

    have

    Similarly we can compute the partial derivative with respect to y. It is defined by

    Note that now x is held fixed. To compute the partial derivative with respect to y we

    differentiate with respect to y and assume x is a constant. For the model problem we

    have

    To determine the derivatives at a particular point in the xy plane, we subsitute the

    coordinates of the point in the formulas for f_x(x,y) and f_y(x,y). For example, at the

    origin x=0 and y=0 and f_x(0,0)=-16 and f_y(x,y)=0. These numbers support the

    arguments based on the plot of the surface and contour plot. The function changes

    more rapidly in the x direction than in the y direction.

    Example

    For the function

    find the partial derivatives of f with respect to x and y and compute the rates of

    change of the function in the x and y directions at the point (-1,2).

    Initially we will not specify the values of x and y when we take the derivatives; we

    will just remember which one we are going to hold constant while taking the

    derivative. First, hold y fixed and find the partial derivative of f with respect to x:

    Second, hold x fixed and find the partial derivative of f with respect to y:

  • 8/8/2019 Understanding Gradient and Divergence

    24/24

    Now, plug in the values x=-1 and y=2 into the equations. We obtain f_x(-1,2)=10 and

    f_y(-1,2)=28.

    Partial Derivatives for Functions of Several Variables

    We can of course take partial derivatives of functions of more than two variables. If f

    is a function of n variables x_1, x_2, ..., x_n, then to take the partial derivative of f

    with respect to x_i we hold all variables besides x_i constant and take the derivative.

    Example

    To find the partial derivative of f with respect to t for the function

    we hold x, y, and z constant and take the derivative with respect to the remaining

    variable t. The result is