Get the derivative of a function_handle in MATLAB
Asked Answered
A

4

6

Is it possible to get the derivative of a function_handle as a other function_handle?

Like:

  fun1 = @(x) x^2;
  % do that ...
  disp(fun2);
    @(x) x*2

I know how to find the derivative of a symbolic function but I can't convert a function_handle to a symbolic function.

I'm new to matlab and I couldn't find any way on doing that. Thanks in advance.

Apprise answered 15/1, 2012 at 11:11 Comment(1)
B
1

The short answer is "No." MATLAB has no idea what the contents of the function_handle mean in a symbolic sense. You're better off creating it using syms in first place.

A longer answer would be either to use the Symbolic Math Toolbox, as suggested by @A Danesh, or an approximation, as suggested by @Andrey.

However, if you're always working with polynomials, then you can store the coefficients as an array and use the following functions:

  • polyval to evaluate
  • conv to multiply
  • deconv to divide
  • polyder to differentiate
  • polyint to integrate
Bellbella answered 15/1, 2012 at 18:58 Comment(0)
T
1
syms x 
f = @(x) x^2 + 1; 
diff(f,x)

Ans:

2*x + 1
Talia answered 12/2, 2019 at 1:30 Comment(0)
W
0

You can get an approximation function:

 delta = 0.0001;
 d = @(x)( (fun1(x+delta) - fun1(x))./delta)
Wiatt answered 15/1, 2012 at 11:27 Comment(0)
O
0

you can't analytically from a function handle.

but if you got the symbolic math toolbox you can derivate the symbolic function and create a function handle from the result.

Outspan answered 15/1, 2012 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.