Cannot differentiate by a defined symbolic function

조회 수: 2 (최근 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 CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by