Is there a efficient way to substitute variables into a symbolic array?

6 views (last 30 days)
In the former version of MATLAB I can use subs to do this:
syms x;
subs([x/2 x^2],[x],[1]);
ans
class(ans)
And I'll get
ans=
0.5 1
ans=
double
Now when I use subs, class(ans) will be syms. It's easy to bypass it by using eval(subs()) instead of subs(). But when i try to run these code I found:
clear all
syms x y
a=[x y];
tic
for i=1:100
subs(a,[x y],[1 1]);
end
toc
I just get more than 1 sec in MATLAB 2014b and about 0.07 sec in MATLAB 2008a. With eval() it's even 0.03 sec slower. I'm working on a computation program, and time efficiency is very important to me. So if there's some way to bypass this annoying (though it can helps remain accuracy in multiply calls of subs) feature of subs?
I've tried matlabFunction, and found it's more slower... 100 calls will consume more than 3 sec. And my input are all vectors, which makes anonymous functions, inline functions and matlabFunction imporper to me.
  2 Comments
Star Strider
Star Strider on 30 Jan 2015
What problem are you solving? The Symbolic Math Toolbox is generally not the best option for iterative routines.
Ben Ma
Ben Ma on 31 Jan 2015
Dealing with some symbolic polynomials, and have to substitute different sets of variables into it's jacobian matrix.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!