Cannot differentiate by a defined symbolic function

28 ビュー (過去 30 日間)
ajshank
ajshank 2021 年 1 月 30 日
回答済み: Shubham Rawat 2021 年 2 月 2 日
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.

回答 (1 件)

Shubham Rawat
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!

カテゴリ

Help Center および File ExchangeSymbolic Variables, Expressions, Functions, and Preferences についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by