# Thread: Question on how to efficiently compute a jacobian..

1. Hello,

I was starting with an equation using hooke's law and with a damping factor appended to it. The equation is to calculate the x,y, and z components of the resulting force, as a vector. The hooke's law portion uses the current position in calculating the force (x, y, and z position components), and the damping part uses the velocity (additional x, y, and z components) in calculating the force.

F(X,V) = -ks(magnitude(X) - r) * (X / magnitude(x)) - b * V
--Here X is the 3 element position vector
--Here V is the 3 element velocity vector
--Here r is the rest length (a constant)
--Here b is a damping constant
--Here magnitude(X) = sqrt(x * x + y * y + z * z)
--Note that magnitude is NOT a constant and must be part of the derivative computation.

I was trying to compute the jacobian matrix resulting from taking the derivative of the force with respect to the position (I am ignoring velocity in this first step).

Thus I will have a 3 X 3 resulting matrix of partial derivatives, where each Force x/y/z component corresponds to a row in the matrix and where each position x/y/z component corresponds to a column in the matrix.

I'm sure there are several resources on the web that give the solution for this and several tutorials that walk through it, but I need to learn to do this without being given the exact answer.

Obviously, it gets tricky above because of the magnitude - you would need the quotient, product, and chain rules from calculus.

I was trying to use these derivative rules to calculate each element of the 9X9 matrix for the derivative of force with respect to position, one by one. However, each calculation was taking about 2 pages (I was substituting findings), and there would be 18 total pages.

I think there are ways to apply derivative rules to vectors directly and better techniques to find Jacobian matrices than what I'm doing. Does anyone know of some good resources that explain this? Most of the derivative rule resources I've found only talk about derivatives for 1-D functions or partial derivatives that are not applied to vectors, and the resources about Jacobians usually talk about the forms easily found in wikipedia without providing much insight into an efficient method for solving them. I may just have looked in the wrong places.

2. Are you sure that this problem is really a three-dimensional problem?

3. Yes, I'm quite sure. I am going to program this into a 3D application in C++ -- it needs x, y, and z coordinates.

4. In that case, perhaps because I am a physicist first and a programmer second, I would be tempted to calculate the spring force in spherical coordinates. Since your damping term is much easier in Cartesian coordinates, I would then convert the spring force to Cartesian using standard expressions for the angles of a radially directed vector. You would have only one spring-force component in spherical coordinates so the process would be easier to keep track of. Getting the length of the spring from the Cartesian coordinates would be one algebraic expression, and the conversion back would be three standard expressions.

I think there are ways to apply derivative rules to vectors directly and better techniques to find Jacobian matrices than what I'm doing. Does anyone know of some good resources that explain this? Most of the derivative rule resources I've found only talk about derivatives for 1-D functions or partial derivatives that are not applied to vectors, and the resources about Jacobians usually talk about the forms easily found in wikipedia without providing much insight into an efficient method for solving them. I may just have looked in the wrong places.
In several dimensionns the derivative is a linear transformation, a matrix once one has selected a set of basis vectors. The matrix that represents the derivative is the Jacobian matrix.

The chain rule from calculus of one variable carries over to higher dimensions pretty much intact, but ordinary multiplication is replaces by matrix multiplication (composition of linear operators).

You can find this in any good book on advanced calculus. One good one is Elements of Real Analysis by Bartle.

Yes, I'm quite sure. I am going to program this into a 3D application in C++ -- it needs x, y, and z coordinates.
It appears to me that the physical model embodied in your equations, since you are ignoring the velocity term, involves a spring in 3 dimensions on a swivel so that it aligns itself with the applied force. That makes the problem effectively 1-dimensional.

Unless you add in a mass, then even when you start to consider the velocity term, any off-axis effects would be rather difficult to interpret physically.

7. Originally Posted by DrRocket
It appears to me that the physical model embodied in your equations, since you are ignoring the velocity term, involves a spring in 3 dimensions on a swivel so that it aligns itself with the applied force. That makes the problem effectively 1-dimensional. Unless you add in a mass, then even when you start to consider the velocity term, any off-axis effects would be rather difficult to interpret physically.
I was going to calculate Jacobians with respect to position and with respect to velocity separately. I think I already have the Jacobian for velocity - it didn't require many derivative rules to figure out. I was going to fine tune mass or other constants later.

Originally Posted by DrRocket
The chain rule from calculus of one variable carries over to higher dimensions pretty much intact, but ordinary multiplication is replaces by matrix multiplication (composition of linear operators).
I'll try looking in my old Calculus book instead of the Internet this time. Do you know of any other specific terms that I might look for while trying to find this rule?

I was about to do all 9 row/column partial derivative computations manually but create mathematical variables on paper to represent portions of the math expressions that keep repeating. If I recognize patterns with those variables, hopefully I can get it into a vector expression afterwards. It should be expressable in a vector form somewhat like the one in section 3.1, equation 3 in: http://graphics.snu.ac.kr/~kjchoi/publication/cloth.pdf. My expression should be slightly little different, however.

I was going to calculate Jacobians with respect to position and with respect to velocity separately. I think I already have the Jacobian for velocity - it didn't require many derivative rules to figure out. I was going to fine tune mass or other constants later.

I'll try looking in my old Calculus book instead of the Internet this time. Do you know of any other specific terms that I might look for while trying to find this rule?
It makes no sense to calculate "Jacobians with respect to position and with respect to velocity separately". The Jacobian is a matrix representation of the derivative, and the derivative, at any given point in the domain of your function, some open set in n-space, is a linear transformation on all of n-space.

Your "old Calculus book" may or may not talk about derivatives in several dimensions. It is usually a topic that one finds in a book on advanced calculus, rather than in an introductory text. Some good books at the level required are:

Calculus on Manifolds -- Michael Spivak (an old paperback that is still one of the very best introductions to multivariable calculus)
Foundations of Analyis -- Joseph Taylor ( relatively new book, but it seems to be a very good one and since I know the author I am confident in its quality)
Elements of Real Analysis -- Robert Bartle (another older classic)
Principles of Mathematical Analysis -- Walter Rudin (a bit more advanced than the others, but Rudin's books have been a staple of mathematical analysis for years)

It might help a bit if you identified your "old calculus book" by title and author. Edition and year of publication would also help.

 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Forum Rules