Cannot differentiate by a defined symbolic function
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Shubham Rawat
am 2 Feb. 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!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Variables, Expressions, Functions, and Preferences finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!