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

7 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2015-1-30
What problem are you solving? The Symbolic Math Toolbox is generally not the best option for iterative routines.
Ben Ma
Ben Ma 2015-1-31
Dealing with some symbolic polynomials, and have to substitute different sets of variables into it's jacobian matrix.

请先登录,再进行评论。

回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by