Cannot differentiate by a defined symbolic function

14 visualizaciones (últimos 30 días)
ajshank
ajshank el 30 de En. de 2021
Respondida: Shubham Rawat el 2 de Feb. de 2021
Hello,
I am unclear about the behaviour of diff() and functionalDerivative() when the second argument is a defined function.
Snippet-1
syms x(t)
f = x^2 + 3*x;
Df = diff( f, x ); % correctly produces: 2*x(t) + 3
Df2 = functionalDerivative( f, x ); % correctly produces: 2*x(t) + 3
Snippet-2
syms x(t)
x = symfun( t^2, t );
f = x^2 + 3*x; % evaluates to an expression in 't'
Df = diff( f, x ); % error: "Arguments, except for first, must not be defined functions"
Df2 = functionalDerivative( f, x ); % also error? "Second argument must be a variable, [or] a symfun .."
In this case, x(t) is infact a symfun object -- and I might have expected a partial derivative expression.
Defining f before x (such that f remains an expression in x) has no effect either. Am I missing something? Why must the second argument not be defined, and why does functionalDerivative not produce 2*x(t) + 3?
Help appreciated! Thanks, and apologies if I am mistaken here.

Respuestas (1)

Shubham Rawat
Shubham Rawat el 2 de Feb. de 2021
Hi Ajay,
In those line it is showing error as x should be a variable symfunction not a defined sym function. Here sym function 'x' is defined.
If you want to calculate differentiation you can do like this
Df = diff(f, t);
Df2 = functionalDerivative( f, x ); %but this won't work
Definition of Functional Derivative
A functional derivative is the derivative of a functional with respect to the function that the functional depends on.
You may reproduce your code by:
syms x(t)
f = x^2 + 3*x;
Df = diff( f, x );
Df2 = functionalDerivative(f, x);
You can see the documentation for furthere information:
Hope this Helps!

Categorías

Más información sobre Symbolic Variables, Expressions, Functions, and Preferences en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by