Partial derivatives of the inline function

2 views (last 30 days)
alpedhuez
alpedhuez on 12 May 2018
Answered: Walter Roberson on 12 May 2018
I have defined an inline function in a script
function a = Test(A,B,C)
I want to symbolically define partial derivatives of this Test function with respect to A, B, C. Please advise.

Answers (2)

Star Strider
Star Strider on 12 May 2018
Your Question lacks detail. The jacobian (link) function is likely what you want. Another option is the gradient (link) function, depending on the result you want.

Walter Roberson
Walter Roberson on 12 May 2018
syms A B C
fun = Test(A,B,C);
Now fun will be a symbolic expression involving A, B, C, that you can calculate gradient of, or can directly calculate
diff(fun, A)
for example.
Note that this will not work if Test uses "if" statements testing the values of the inputs, or does logical indexing based upon the values, or if it initializes vectors or arrays to zeros() and tries to assign values calculated from A, B, C into them. Sometimes you need to change a function a bit to make it usable with symbolic inputs. Sometimes you need to resort to tests such as
if issym(A) || issym(B) || issym(C)
y = piecewise(....);
else
if A < pi || B > sqrt(2)
y = 11;
else
y = 9;
end
end
-- that is, sometimes you need to test if you are doing symbolic work and create a piecewise() expression because you cannot test unresolved symbols against specific numbers.

Products

Community Treasure Hunt

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

Start Hunting!