MATLAB: Why is symbolic substitution so slow and what are the faster alternatives?
<p>On my machine, the following code:</p>

<pre><code>for i=1:200
    1+2+5;
end;
</code></pre>

<p>runs in 0.000180 seconds.</p>

<p>Now, this code:</p>

<pre><code>syms x y z
f(x,y,z) = x + y+z;

for i=1:200
    f(1,2,5);
end;
</code></pre>

<p>is much slower (6.193909 seconds).</p>

<p>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.</p>

<p>Is there any alternative other than doing everything manually (writing the full derivatives by hand)?</p>