f(x) =

Hi Paul,

As per my understanding, you would like to get more clarification on how “diff” function works in MATLAB when operated using symbolic variables.

Let me discuss few of the scenarios for f(x) = x^n when passed as input to the “diff” function.

- Case 1 : diff(f(x),x,1) - Output of this will be the derivative of function “f” with respect to “x”, which is n*x^(n-1)
- Case 2 : diff(f(x),x,2)- This gives the second derivative of “f” with respect to “x” which is n*(n-1)*x^(n-2)
- Case 3 : diff(f(x), x, n) - This means that “f” is differentiated with respect to “x” and the result is then differentiated with respect to “n”. Which means the output will be x^(n-1) + n*log(x)*x^(n-1)
- Case 4 : diff(x^5, x, n) - As stated in Case 3, x^5 is first differentiated with respect to “x”, which gives 5*x^4. Now, if this is differentiated with respect to “n”, we get 0 because 5*x^4 is independent of n.
- Case 5 : diff(f(x), x, n+1) -This gives error because performing arithmetic operations is not allowed between symbolic variables and constants.

For further reference, please refer to the following documentation:

I hope this helps.