MATLAB: Why is symbolic substitution so slow and what are the faster alternatives?
Date: 2023-01-24 12:40:09
On my machine, the following code:
for i=1:200
1+2+5;
end;
runs in 0.000180 seconds.
Now, this code:
syms x y z
f(x,y,z) = x + y+z;
for i=1:200
f(1,2,5);
end;
is much slower (6.193909 seconds).
For my code, I need to write the derivatives of several complicated functions of 3 variables, and then plug in all the integer points in a given domain. It would help A LOT to be able to do symbolic differentiation and then plugging in, but this seems amazingly slow.
Is there any alternative other than doing everything manually (writing the full derivatives by hand)?