Diff, derivative does not exist

10 views (last 30 days)
James_111
James_111 on 27 Jan 2019
Edited: Walter Roberson on 27 Jan 2019
My code is:
fun=@(x) abs(x-1);
pfun=@(x) diff(fun(x),x);
feval(pfun,1)
It didn't return any answer after running the code. My general point, if we want to use Matlab to take the derivative of a function, but the derivative of this funtion does not exist everywhere (like the point 1 in fun(x)). How Matlab return the value? If there are infinite numbers of such points, how Matlab deal with this issue? Any help is very appreciated!
  4 Comments
Walter Roberson
Walter Roberson on 27 Jan 2019
Edited: Walter Roberson on 27 Jan 2019
You are not doing a symbolic derivative. You are evaluating pfun(1) which is pfun with numeric input. You pass that numeric input to abs(x-1), getting a numeric output. Your diff() of a numeric input is finite differences, not derivative.
James_111
James_111 on 27 Jan 2019
Thank you so much for pointing out the "finite difference", Walter!

Sign in to comment.

Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!