Notices
Results 1 to 9 of 9

Thread: Gradient question

  1. #1 Gradient question 
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    I haven't every had much use for gradients, but I'm trying to work something out, and it doesn't look like it's working. I can't tell if it's my math or my integrator though (Verlet integration ATM).

    What I've got is a scalar field over all of space, , where is some (smooth) noise function and is a set of points.

    I'm looking for , and if I'm not horribly misunderstanding something , so I should be able to calculate the gradient of each piece separately and add them together.

    For a noise function, I'm using . Then . The constants for that are picked from a normal distribution.

    For the other half, I calculated

    Now, the specific problem I'm having is that each is a point moving around according to the gradient at its position. Specifically, I'm setting its acceleration to be equal to the gradient (ignoring its own contribution). Now, I think that, generally, a point shouldn't be able to reach places where the field is significantly stronger than where it started (with no initial velocity), but the points tend to set off in one direction passing over areas with much higher field strength with only a little curvature. So my question is, am I doing the math wrong, am I making unfounded assumptions or is my integrator just not up to the task?

    Edit: Hmm... A little further investigation showed that I was attempting to use Verlet integration with a variable time step. :x Oh well. With that fixed, it looks a lot more stable, but I'd still like someone to check if my math is about right.


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Sophomore
    Join Date
    Jan 2008
    Location
    Texas
    Posts
    158
    Are you calculating the Unit Gradient Vector for the second one? I don't see why you are dividing by the magnitude raised to the fourth.

    All I know about gradients is that they are normal to the original functions at all locations.

    Don't you just take the partial derivative of each with respect to each vector, and then add them up? I'm not really saying you did anything wrong, I guess I just don't know how you took the derivative of the second one. Its probably because I don't really understand how to differentiate a "set of points"

    Edit: by the way, the rest it makes sense to me.


    Reply With Quote  
     

  4. #3 Re: Gradient question 
    . DrRocket's Avatar
    Join Date
    Aug 2008
    Posts
    5,486
    Quote Originally Posted by MagiMaster
    I haven't every had much use for gradients, but I'm trying to work something out, and it doesn't look like it's working. I can't tell if it's my math or my integrator though (Verlet integration ATM).

    What I've got is a scalar field over all of space, , where is some (smooth) noise function and is a set of points.

    I'm looking for , and if I'm not horribly misunderstanding something , so I should be able to calculate the gradient of each piece separately and add them together.

    For a noise function, I'm using . Then . The constants for that are picked from a normal distribution.

    For the other half, I calculated

    Now, the specific problem I'm having is that each is a point moving around according to the gradient at its position. Specifically, I'm setting its acceleration to be equal to the gradient (ignoring its own contribution). Now, I think that, generally, a point shouldn't be able to reach places where the field is significantly stronger than where it started (with no initial velocity), but the points tend to set off in one direction passing over areas with much higher field strength with only a little curvature. So my question is, am I doing the math wrong, am I making unfounded assumptions or is my integrator just not up to the task?

    Edit: Hmm... A little further investigation showed that I was attempting to use Verlet integration with a variable time step. :x Oh well. With that fixed, it looks a lot more stable, but I'd still like someone to check if my math is about right.
    I have not checked your calculation in gory detail, but it looks right.

    I think your intuition is correct, since what you are doing seems to be basically a steepest descent algorithm (simulating a ball rolling around on a curved sheet) so you should not be able to "climb above" the starting point if you ignore effects of numerical error and step size.
    Reply With Quote  
     

  5. #4  
    . DrRocket's Avatar
    Join Date
    Aug 2008
    Posts
    5,486
    Quote Originally Posted by GenerationE
    Are you calculating the Unit Gradient Vector for the second one? I don't see why you are dividing by the magnitude raised to the fourth.
    Note the vector term in the numerator, which provides the "direction" and is of the same magnitude as the norm, so essentially the division winds up being by the third power, which is what you would expect.

    All I know about gradients is that they are normal to the original functions at all locations.
    That doesn't make sense. One applies the gradient to a scalar field to produce a vector field. There is no notion of perpendicularity of a vector with respect to a scalar.

    Don't you just take the partial derivative of each with respect to each vector, and then add them up?
    Not really, except in a very loose sense. You don't add them up, but rather treat them as components of a vector. You might consider this as addition of three vectors, one in the direction of each unit basis vector, but that is a somewhat confusing way to describe the gradient operator. The important point is that the gradient operator is applied to a scalar field to produce a vector field.

    I'm not really saying you did anything wrong, I guess I just don't know how you took the derivative of the second one. Its probably because I don't really understand how to differentiate a "set of points"

    Edit: by the way, the rest it makes sense to me.
    You are not differentiating a set of points, but rather a function defined on, in this case 3-space, with real values. The derivative, at a point, of such a function is a linear function from 3-space to the real numbers, which can be identified with a vector (or a 1x3 matrix).
    Reply With Quote  
     

  6. #5  
    Forum Sophomore
    Join Date
    Jan 2008
    Location
    Texas
    Posts
    158
    So a gradient isn't perpendicular to the level curves of a function? I thought if you had a function say , or something of this nature. The gradient then becomes or like you said, 2. Sorry for not making that clear.

    Anyways, isn't the point of this to give you a direction normal to the level curves? Like you said steepest decent, something that points in the direction of steepest assent or decent. Unless you dotted your gradient with a unit vector, then I guess it takes on the direction of the unit vector.



    I see how this,

    Note the vector term in the numerator, which provides the "direction" and is of the same magnitude as the norm, so essentially the division winds up being by the third power, which is what you would expect.
    works. It looked confusing to me at first.

    The important point is that the gradient operator is applied to a scalar field to produce a vector field.
    Does this mean the scalar field is somehow given the direction of gradient at all locations? Would you need to first divide the gradient by it's magnitude to give you a unit vector? And then apply it to the scalar field?
    Reply With Quote  
     

  7. #6  
    . DrRocket's Avatar
    Join Date
    Aug 2008
    Posts
    5,486
    [quote="GenerationE"]So a gradient isn't perpendicular to the level curves of a function? I thought if you had a function say , or something of this nature. The gradient then becomes or like you said, 2. Sorry for not making that clear.[quote]

    Note that in your earlier post you did not talk about level curves, but about the scalar field itself. Sure the gradient is perpendicular to the level curves.

    Anyways, isn't the point of this to give you a direction normal to the level curves? Like you said steepest decent, something that points in the direction of steepest assent or decent. Unless you dotted your gradient with a unit vector, then it takes on the direction of the unit vector.
    I guess it depends on what you think the point is. Apparently I look at the gradient operator from a different viewpoint than do youl.


    Does this mean the scalar field is somehow given the direction of gradient at all locations? Would you need to first divide the gradient by it's magnitude to give you a unit vector? And then apply it to the scalar field?
    I don't understand what you are talking about here. Scalar fields are fields of scalars, and scalars don't have a direction. Vectors have a direction.
    Reply With Quote  
     

  8. #7  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    I think I got it working, and yeah, it's basically for a group of charged (all same charge) balls rolling around on a warped sheet. Unfortunately, it doesn't do what I wanted it to. The balls could be considered to have something like a potential energy, which is the highest point it could reach. This can only really change by the balls' interactions with each other.

    The problem with this is that the balls won't settle into the pockets unless the total energy of the group is lower than the walls, which doesn't happen very often, especially since the rogues from other groups can come by and knock them out of place. I could add a friction term, but then everything would probably settle too much. Is there anything else I could try though?
    Reply With Quote  
     

  9. #8  
    Forum Sophomore
    Join Date
    Jan 2008
    Location
    Texas
    Posts
    158
    Quote Originally Posted by DrRocket

    Does this mean the scalar field is somehow given the direction of gradient at all locations? Would you need to first divide the gradient by it's magnitude to give you a unit vector? And then apply it to the scalar field?
    I don't understand what you are talking about here. Scalar fields are fields of scalars, and scalars don't have a direction. Vectors have a direction.
    I know that scalars don't denote any direction, only magnitude. I guess what I mean is:

    Say you have a scalar field, I don't know what it would look like but I guess it would just assign magnitudes to different points in the field. How do you turn the Scalar field into a vector field? I'm guessing some how you use the gradient's direction and the scalars magnitude?


    Also thanks for the patience, I know I don't always understand things perfectly right away, but it helps to have discussions about these things. It helps me grasp the physical and meaning of operations such as the gradient, which is essential if you want to understand it's real life application.
    Reply With Quote  
     

  10. #9  
    . DrRocket's Avatar
    Join Date
    Aug 2008
    Posts
    5,486
    Quote Originally Posted by GenerationE
    Quote Originally Posted by DrRocket

    Does this mean the scalar field is somehow given the direction of gradient at all locations? Would you need to first divide the gradient by it's magnitude to give you a unit vector? And then apply it to the scalar field?
    I don't understand what you are talking about here. Scalar fields are fields of scalars, and scalars don't have a direction. Vectors have a direction.
    I know that scalars don't denote any direction, only magnitude. I guess what I mean is:

    Say you have a scalar field, I don't know what it would look like but I guess it would just assign magnitudes to different points in the field. How do you turn the Scalar field into a vector field? I'm guessing some how you use the gradient's direction and the scalars magnitude?


    Also thanks for the patience, I know I don't always understand things perfectly right away, but it helps to have discussions about these things. It helps me grasp the physical and meaning of operations such as the gradient, which is essential if you want to understand it's real life application.
    You don't turn a scalar field into a vector field.

    I'm not sure what you are getting at but maybe this discussion will help:

    If you have a scalar field and take the gradient you get a vector field. If you integrate that vector field along a path (a line integral) you get the difference between the value of the scalar field a the end points, and in particular the integral around a closed curve is zero. That makes the vector field "conservative" in the sense of physics and the scalar field is called the potential for the vector field. So if the vector field represents the electric field, then the scalar field is the potential (volts).

    Conversely, if you have a vector field for which the curl is always zero then there exists a scalar field the gradient of which is the vector field.

    Scalar fields and vector fields may be related as in the previous discussion, but they are also distinctly different things and you don't turn one into the other except by applying a differential operator, like the gradient. This notion can be made more precise via the theory of differential forms that comes up in the theory of differentiable manifolds and differential geometry.
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •