Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

how do you do symbolic differentiation on function handle?

Date: 2022-07-28 10:58:41

Say if i define the following: 

 

 g = @(x) x/sqrt(x^2+1)

How do i get the derivative function for g, which i can then use to evaluate at different points?

I tried the symbolic math toolkit, and tried the following: 

 

>> syms x

>> f = x/sqrt(x^2+1)

f =

x/(x^2 + 1)^(1/2)

>> diff(f)

ans =

1/(x^2 + 1)^(1/2) - x^2/(x^2 + 1)^(3/2)

However, i cannot figure out how to turn this into a function handle/evaluate at different points. However, i prefer doing differentiation on function_handle.

Thank you very much! 

Answer: 

You can use matlabFunction to convert a symbolic equation to a function. For example: 

 

syms x1 x2;
f1 = x1^2+x2^2;
Df1 = jacobian(f1, [x1 x2]);
Df1 = matlabFunction(Df1);

Then Df1(0, 0) returns [0 0] as expected.


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com