Ask Your Question
1

Is matrix calculus possible within sagemath?

asked 2016-02-02 10:20:41 +0100

morph gravatar image

For example, is it possible to compute the following partial derivative in Sagemath:

$$ A_{ij} = \frac{\partial e_{ij}(x)}{\partial x_i} = \begin{pmatrix} -R_{ij}^T R_i^T & R_{ij}^T \frac{\partial R_i^T}{\partial \theta_i} (t_j - t_i) \\ 0^T & -1 \end{pmatrix} $$

for

$$ e_{ij}(x) = \begin{pmatrix} R_{ij}^T (R_i^T (t_j - t_i) - t_{ij}) \\ \theta_j - \theta_i - \theta_{ij} \end{pmatrix} $$

and

$$ x_i^T = (t_i^T, \theta_i) $$ $$ z_{ij}^T = (t_{ij}^T, \theta_{ij}) $$

The background shouldn't be important, but just for completeness: this example is an excerpt from Robotics, especially the problem of Pose Graph Simultaneous Mapping and Localization. $x_i$ defines a pose in $\mathbb{R}^2$ with translation $t_i$ and rotation angle $\theta_i$, $z_{ij}$ defines a transform between two poses and $e_{ij}(x)$ defines the error between two poses, i.e. a transform between them.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-03-03 23:55:06 +0100

dan_fulea gravatar image

It is unclear what $R_i$, $R_{ij}$ are in the context. (And of what shape.) But it should be possible. For instance:

sage: for k in range(10):    var('t%s' % k);
sage: Expression = t0*t1 - t3 + exp(t4*t5-t9^100) - sin(t7)    # sorry, i had a bad day...
sage: for k in range(10):
....:     print "diff( Expression, t%s ) = %s" % ( k, diff( Expression, eval( "t%s" % k ) ) )
....:     
diff( Expression, t0 ) = t1
diff( Expression, t1 ) = t0
diff( Expression, t2 ) = 0
diff( Expression, t3 ) = -1
diff( Expression, t4 ) = t5*e^(-t9^100 + t4*t5)
diff( Expression, t5 ) = t4*e^(-t9^100 + t4*t5)
diff( Expression, t6 ) = 0
diff( Expression, t7 ) = -cos(t7)
diff( Expression, t8 ) = 0
diff( Expression, t9 ) = -100*t9^99*e^(-t9^100 + t4*t5)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-02-02 10:20:41 +0100

Seen: 677 times

Last updated: Mar 03 '17