On 28/10/2019 11:03, Ash wrote:
Hello
I am trying to develop equations of motion using sympy of a complex
system. It takes 4-5 minutes to get the mass matrix (M) and coriolis
vector (C). Hence I decided to use sympy's codegen and try to make it
fast.
I can write my equations as
d^2 *q*/ dt^2 = M_inverse (Tau - C - G)
but M, C, Tau (torque) and G(gravity) are defined with respect to
state variables and its derivatives. And I cant figure out how to do it.
I am attaching a simple two degree of freedom planar robot's code for
easy understanding of my problem. My state variables are the angles
q1(t) and q2(t) (dynamic symbols). There are other variables like
lengths, mass, inertia of the links which are defined as symbols.
M(q(t)), C(q(t), dq(t)), G(q(t)) matrices are derived symbolically
(line 14). My doubt is if I want to play around with the numerical
values of the variables in M, C, and G, how can I efficiently generate
code and cythonize and build wrapper?
Any help would be really appreciated
I used to work as a Mathematica consultant, and I have seen a number of
Mathematica users concerned about performance issues. There are plenty
of subtle ways to make Mathematica code run slowly - often dramatically
so. I am sure the same is true of all algebra systems.
As a simple example from Mathematica, simply ensuring that every
component of a numerical matrix is the same type can improve performance
a lot. It is so easy to write some zero components as 0 (i.e. an
integer) as opposed to 0.0 (a real). If you do that in a language like
Fortran, the compiler will automatically convert the components of the
matrix to the type of the variable that holds them, but not in
Mathematica or (I think) SymPy.
I am not quite sure if your basic problem is speed or formulating your
problem. However, if you have a problem with speed, it would definitely
be worth taking the time to extract a simple example of a SymPy
calculation that seems slow to you.
David
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/6248732c-59ee-3654-52d0-d779d267d769%40dbailey.co.uk.