How do I symbolically work with implicit functions (i.e., "x(t)") within the Symbolic Math Toolbox?

4 ビュー (過去 30 日間)
I would like to find the derivative of:
E1 = x' * sin(x)
where "x" and "y" are functions of time "t".
I tried:
syms x t
Dx= diff(x,t)
I receive the result:
Dx =
0
In addition
syms x y t
Dx= diff(x(t),t)
??? Unable to find subsindex function for class sym.

採用された回答

MathWorks Support Team
MathWorks Support Team 2011 年 11 月 8 日
The following example demonstrates how you can represent "x" as functions of time "t" and perform differentation on it:
Example 1:
syms t
x = sym('x(t)'); % x(t)
E1 = diff(x) * sin(x)
E2 = diff(E1,t)
pretty(E1)
pretty(E2)
The solution for E1:
/d \
|-- x(t)| sin(x(t))
\dt /
The solution for E2:
/ 2 \
|d | /d \2
|--- x(t)| sin(x(t)) + |-- x(t)| cos(x(t))
| 2 | \dt /
\dt /
The following example demonstrates how to substitute 'x(t)' with an explicit definition.
Example 2:
% Order of the derivative
n = 2
% Define symbolic variables.
syms t
x = sym('t^2');
f = sym('f(x)');
% SUBS is used to substitute definition of x
f_subs = subs(f);
disp('Diff f_subs wrt to t')
pretty(diff(5*f_subs + t^2,t,n))
disp(' ')
disp('Diff f_subs wrt to x(t)')
pretty(diff(5*f_subs + t^2,x,n))
disp(' ')
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 2 月 22 日
編集済み: MathWorks Support Team 2022 年 2 月 23 日
From R2015a onwards, there is a new functionalDerivative() that would allow you to take the derivative with respect to a function.
Walter Roberson
Walter Roberson 2016 年 2 月 22 日
From about R2011b onwards, instead of using
syms t
x = sym('x(t)');
you can also use
syms t x(t)
or even
syms x(t)
which will notice if t is not already defined as a symbol and will define it as a symbol if it needs to.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by