Find Derivative of Numeric Function

2 views (last 30 days)
Diego Torres-Siclait
Diego Torres-Siclait on 11 Feb 2021
Commented: John D'Errico on 11 Feb 2021
Take for example
f = @(x) x^3;
Is there a builtin function to find the derivative?

Answers (1)

David Hill
David Hill on 11 Feb 2021
I am not sure what the best way is, but I would use symbolic and then convert.
syms x;
f=x^3;
df=str2func(['@(x)',char(diff(f))]);
  1 Comment
John D'Errico
John D'Errico on 11 Feb 2021
Lol. I'm not sure there is a best way. An alternative might be:
f = @(x) x^3;
syms x
fp = matlabFunction(diff(f(x)))
fp = function_handle with value:
@(x)x.^2.*3.0

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!