Alex Turner
Alex Turner

Reputation: 101

How to use Diff function

I'm doing an algorithm and at some point I have to calculate the derivative of a function, I tried to use diff but it didn't work.

I have the function defined like this:

function y = funcionF(x)
   y = x^3 - 3*x^2 -10;
end

I tried diff(funcionF) but I get this error:

Not enough input arguments.

Is there a way to make it work or is mandatory to use a Symbolic Function?

Upvotes: 0

Views: 510

Answers (1)

dmedine
dmedine

Reputation: 1563

https://au.mathworks.com/help/symbolic/differentiation.html

You need to define the symbols using syms which requires the Symbolic Math Toolbox, which I don't have, but this should work (according to the documentation):

>> syms x
>> f = x^3 - 3*x^2 - 10;
>> diff(f)

should give you something like

ans = 
3*x^2-6*x

Upvotes: 1

Related Questions