performance issue of evaluation symbolic expression in Matlab 2014a

1 view (last 30 days)
Hello, Is there any fast way to have evaluate the numeric value in latest version 2014a? For example the following simple test code
tic
syms f phi
f = phi^2 - phi - 1;
v1 = randn(1000,1);
val = double( subs(f,phi,v1) );
toc
In Matlab 2012a you can write the line " val = double( subs(f,phi,v1) ); " as val = subs(f,phi,v1); " directly without "double()" to get the value. But in version 2014a you will get symbolic expression if you do not use double(). However for above same code. The speed of computation is massively slower than the old version, Especially when my symbolic expression is more complicated.
For my PC the above code has the following results:
  • It takes about 0.006 seconds on version 2012a
  • It takes about 0.190 seconds on version 2014a
It's 32 times slower in the newer version!!! My real application cannot executed in the new version due to the speed. Any experts can give me some advices on this?
Many thanks

Answers (1)

Star Strider
Star Strider on 13 Jul 2014
Edited: Star Strider on 13 Jul 2014
On my laptop with R2014a, casting it as a function is about 3¼ times faster than using subs. Using double actually slows it down a bit.
Illustrating:
tic
syms f phi
f(phi) = phi^2 - phi - 1;
v1 = randn(1000,1);
val = double(f(v1));
toc
That should also be an option in R2012a.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!