Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Faster symbolic substitution

152 views
Skip to first unread message

Dennis

unread,
Dec 5, 2008, 12:15:03 PM12/5/08
to
Hi,

I have a large symbolic Jacobian matrix (400 elements 30variables). I am using "subs" to evaluate it at every iteration (of my algorithm). However, this is taking too long. Any tricks to make it swifter?

Thanks,
Dennis

Alan Weiss

unread,
Dec 5, 2008, 8:47:10 PM12/5/08
to

Try using matlabFunction. It takes a long time to generate a file, but
after that things will be swift.
http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/brt7nuv.html#brt7nyh

Alan Weiss
MATLAB mathematical toolbox documentation

emre

unread,
Dec 5, 2011, 4:48:08 PM12/5/11
to
Alan Weiss <awe...@mathworks.com> wrote in message <ghcliu$1am$1...@fred.mathworks.com>...
Even if i didnt ask the question for fast substitution, this comment has been really life saver for me. I was working on some online intelligent learning algorithm and it needed to be fast at each iteration. Your comment helped a lot to reduce a very complicated symbolic matrix substitution time from hours to seconds! Thanks very much..

Alan Weiss

unread,
Dec 5, 2011, 5:04:26 PM12/5/11
to
I'm glad the suggestion proved valuable. Thanks you for letting me know
that it helped.

Carlos

unread,
Nov 21, 2012, 7:35:08 AM11/21/12
to
Hi, I have the same problem with large 20x20 symbolic jacobian and I can´t figure out how to use Matlabfunction to solve my problem.
The first is to build the handle G
G = matlabFunction(Jacobian)
My jacobian has 20 variables x1..x20.
So if I did G(0,0,0...0) Would I obtain the a numerical matrix result of substituting the 20 variables by zero.
Thank you

Christopher Creutzig

unread,
Nov 22, 2012, 4:33:05 AM11/22/12
to
Basically, yes. It probably wouldn't hurt to explicitly tell
matlabFunction the order of variables you expect, though.

If this doesn't work as expected, please create a small complete example
showing what you see and saying what you expected to see instead.


Christopher




Jan

unread,
Jun 7, 2014, 11:11:07 AM6/7/14
to
Hello,

I have got similar problem as guys above.
I am working on description of robotic arm. It is composed of six serial transformations - result of previous transformation is one of inputs of the next transformation. And every transformation is composed of few "subtransformations". The problem is, that creation of last tranformation is extremely slow. It took more than one half of a day and it still was not finished. I have to use 33 symbolic variables and the final equations are really complex. I have already found out, that I can rapidly decrease computing time (I used this in case, which was not so complex) by substituting inputs dependent on previous result by some general vector and than use "subs" to create final expression (see exapmle). But in this case, I have got so complex expressions, that either with this help computing simply takes too long.
I have already found out, that I can create function handle via matlabFunction and accelerate substitution of numbers, but is there any way of making the process of creating the "general expression" faster, please?

Example
Suppose I am interested in final vector R2 (dim 3), but following sequence takes too long

R0=transformation(a1,a2,a3...,initial vector);
R1=transformation(b1,b2,b3....,R0);
R2=transformation(c1,c2,c3....,R1);

So i used something like

R0=transformation(a1,a2,a3...,initial vector);
R1=transformation(b1,b2,b3....,S);
R2=transformation(c1,c2,c3....,R1);

R2=subs(R2,S,R0)

what increased the speed of the code.

(But now I have got six transformations and subs does not help a lot, do you know, how implement matlabFunction into this example? And would it be useful?)

Thank you very much!

Jan

Christopher Creutzig

unread,
Jun 11, 2014, 8:39:42 AM6/11/14
to
On 6/7/14 5:11 PM, Jan wrote:

> I have already found out, that I can create function handle via matlabFunction and accelerate substitution of numbers, but is there any way of making the process of creating the "general expression" faster, please?

Without seeing the actual formulas, this is just stabbing in the dark,
but you may find it useful to call simplify on your intermediate
results. Also, if you are not actually interested in the symbolic
result, but only want it to plug in numbers, using a sequence of
functions generated by matlabFunction may be a better option.

> So i used something like
>
> R0=transformation(a1,a2,a3...,initial vector);
> R1=transformation(b1,b2,b3....,S);
> R2=transformation(c1,c2,c3....,R1);
>
> R2=subs(R2,S,R0)
>
> what increased the speed of the code.
>
> (But now I have got six transformations and subs does not help a lot, do you know, how implement matlabFunction into this example? And would it be useful?)

fR0 = matlabFunction(R0, ...);
fR2 = matlabFunction(R2, ...);
value = fR2(c1,c2,...,fR0(a1,a2,...))


HTH,

Christopher

0 new messages