I am studying robotics, and I am trying to write a Matlab code for computing the derivative of the jacobian matrix.

The formula for computing the derivative of the Jacobian is the following:

enter image description here

so it has been done a derivation with respect to time and it has been applied the chain rule.

I know how to do this computation by hand, but it takes really a long time if the Jacobian is large, and moreover if then I have to do some calculations with the derivative of the Jacobian it is hard without the code.

I have found this question here on Stack Exchange Robotics where a code has been posted:

Derivative of a Jacobian matrix

which is similar(it is the same, I copied it but I changed T with q) to:

clear all
syms q1 q2 q3 t;

q1(t) = symfun(sym('q1(t)'), t);
q2(t) = symfun(sym('q2(t)'), t);
q3(t) = symfun(sym('q3(t)'), t);

J11 = -sin(q1(t))*(a3*cos(q2(t) + q3(t)) + a2*cos(q2(t)))

dJ11dt = diff(J11,t)

but if I use this code I get an error which says:

Error using sym>convertChar (line 1537) Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.

can somebody please help me?

  • $\begingroup$ On Robotics we are fortunate enough to have MathJax support enabled, allowing you to easily create subscripts, superscripts, fractions, square roots, greek letters and more. This allows you to add both inline and block element mathematical expressions in robotics questions and answers. For a quick tutorial, take a look at How can I format mathematical expressions here, using MathJax? $\endgroup$
    – Mark Booth
    May 17, 2020 at 9:34
  • $\begingroup$ ![enter image description here](i.sstatic.net/WKIkG.png) Hi, J.D., I am sorry that I have to reply by 'answer' instead of 'comment' because I have not enough reputations, would please tell me which paper does this formula come from? Thanks in advance! $\endgroup$
    – BrP Al
    Dec 9, 2020 at 12:10

1 Answer 1


To answer your solution, specifically, all you need to do is:

clear all
syms q1 q2 q3 t a3 a2;

q1(t) = symfun(str2sym('q1(t)'), t);
q2(t) = symfun(str2sym('q2(t)'), t);
q3(t) = symfun(str2sym('q3(t)'), t);

J11 = -sin(q1(t))*(a3*cos(q2(t) + q3(t)) + a2*cos(q2(t)))

dJ11dt = diff(J11,t)

But if you're interested, there is a paper you might want to check that solves for the Jacobian Derivative $\dot{J}(q)$ analytically, (Rhee, J. Y., & Lee, B., 2017). The authors compare the method you presented with their own in terms of computation time. It is significantly faster.

The method they presented is summarized in the following algorithm.

$$ \overline{\underline{\bf{\text{Algorithm 1}}\textrm{ Jacobian and Jacobian Differentiation}}}\\ \begin{array}{lll} 1: & \omega_0^0 \leftarrow\left[0,0,0\right]^T & \\ 2: & z_0^0 \leftarrow\left[0,0,1\right]^T & \\ 3: & \pmb{J}_1 \leftarrow \left[\begin{matrix} z_0^0\times d_n^0 \\ z_0^0\end{matrix}\right] & \\ 4: & \bf{\text{for }} \textrm{i = 2 to n } \bf{\text{do}} & \triangleright \textrm{ Jacobian Computation loop} \\ 5: & \quad \pmb{J}_i = \left[\begin{matrix} z_{i-1}^0 \times d_{i-1,n}^0 \\ z_{i-1}^0\end{matrix}\right] & \\ 6: & \quad \omega_{i-1}^0 \leftarrow w_{i-2}^0 + z_{i-2}^0\dot{q}_{i-1} \\ 7: & \bf{\text{end for}} & \\ 8: & \beta \leftarrow J_{v,i}\dot{q}_i & \\ 9: & \bf{\text{for }} \textrm{i = n to 2 } \bf{\text{do}} & \triangleright \textrm{ Jacobian Differentiation loop}\\ 10: & \quad \dot{z}_{i-1}^0 \leftarrow \omega_{i-1}^0 \times z_{i-1}^0 & \\ 11: & \quad \alpha \leftarrow \left[0,0,0\right]^T & \\ 12: & \quad \bf{\text{for }} \textrm{j = 1 to i-1 } \bf{\text{do}} \\ 13: & \qquad \alpha \leftarrow \alpha + z_{j-1}^0 \times \left(d_n^0 - d_{i-1}^0\right)\dot{q}_j & \\ 14: & \quad \bf{\text{end for}} & \\ 15: & \quad \dot{J}_i = \left[\begin{matrix} \left(\dot{z}_{i-1}^0\right) \times (d_{n}^0- d_{i-1,n}^0) + z_{i-1}^0 \times\left(\alpha + \beta\right) \\ \dot{z}_{i-1}^0 \end{matrix}\right] & \\ 16: & \quad \beta \leftarrow \beta + J_{v,i-1}\dot{q}_{i-1} & \\ 17: & \bf{\text{end for}} & \\ 18: & \dot{J}_1 = \left[\begin{matrix} z_0^0 \times \beta \\ \left[0,0,0\right]^T \end{matrix}\right] & \\ \end{array} \\ $$

  • 2
    $\begingroup$ You're using a verbose syntax for the symbolic functions: q1(t) = symfun(str2sym('q1(t)'), t);. The new(er?) way to define it is just syms q1(t). $\endgroup$
    – Chuck
    Dec 9, 2020 at 16:03
  • $\begingroup$ You're probably right. You're welcome to edit my answer since I don't have the energy. $\endgroup$
    – Spaceman
    Dec 12, 2020 at 16:19
  • $\begingroup$ Eh I don't especially care either, for the purposes of this answer. Just wanted to give you a pro tip for your future Matlab use :) $\endgroup$
    – Chuck
    Dec 13, 2020 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.