Computing mixed derivatives in MATLAB using syms and diff
<p>I'm using MATLAB 2012b.
I want to get d²/dxdy of a simple function: </p>

<pre><code>f(x,y) = (x-1)² + 2y²
</code></pre>

<p>The documentation states that I can use <code>syms</code> and <code>diff</code> as in the following example:</p>

<pre><code>&gt; syms x y
&gt; diff(x*sin(x*y), x, y)
ans =
    2*x*cos(x*y) - x^2*y*sin(x*y)
</code></pre>

<p>But doing the same I got the wrong answer:</p>

<pre><code>&gt; syms x y
&gt; f = (x-1)^2 + 2*y^2;
&gt; diff(f,x,y)
ans = 
    4*y
</code></pre>

<p>The answer is right if I use <code>diff</code> like this:</p>

<pre><code>diff(diff(f,x),y)
</code></pre>

<p>Well, it's not a problem for me to use it this way, but nevertheless why is the first variant not working? Is it a version issue? </p>