MATLAB: Derivative of a Function

derivative function

Is there a way to input a function as "g=@(x) exp(x^2-2);" and take the derivative?

Best Answer

  • If you have the Symbolic Toolbox:
    >> g = @(x) exp(x^2-2)
    g =
    @(x)exp(x^2-2)
    >> syms x
    >> diff(g(x))
    ans =
    2*x*exp(x^2 - 2)