This question involves how to access certain dervatives of arbitrary (i.e., unknown) functions using the symbolic toolbox. This is an issue that arises when you try to take derivatives of a composite function, where both functions that make up the composite one are arbitrary/unknown. I'm using R2018b.
My question is best illustrated with an example:
syms f(x) g(x)dgfx = diff(g(f(x)),x)
returns
dgfx = D(g)(f(x))*diff(f(x), x)
This expression has two different notations for derivatives. diff(f(x), x) is just the representation of the derivative of f, which is fine. This is the format I expect, and I can "access" this derivative representation and, for example, replace it with a variable using subs, such as:
syms asubs(dgfx,diff(f(x), x),a)
which returns
ans = a*D(g)(f(x))
dgfx also includes the derivative notation D(g)(f(x)), which captures the derivative of the g function. The problem I'm having is that I cannot figure out how to access this representation in the same way as with the diff notation in order to replace this derivative with a variable. For example,
subs(dgfx,D,a)subs(dgfx,D(g),a)
both return the error, "Undefined function or variable 'D'." So it seems neither D nor D(g) are functions I can access. However, Matlab does seem to recognize D as a function of some kind, since, for example, taking derivatives again:
diff(dgfx,x)
yields
ans = D(D(g))(f(x))*diff(f(x), x)^2 + D(g)(f(x))*diff(f(x), x, x)
We now have a term involving D(D(g))(f(x)), which captures the second-order derivative of g. So clearly Matlab recognizes D(g) as a function whose derivative can be taken. The question I have is, how can I access this in a way that will allow me to replace D with a variable?
Best Answer