Cannot differentiate by a defined symbolic function
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Shubham Rawat
2021-2-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Preferences 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!