在符号表达式中替换函数的导数 [英] substitute the derivative of a function in a symbolic expression
问题描述
In Matlab the derivative of a function can be represented symbolically as
>> syms t
>> syms x(t)
>> diff(x,t)
ans(t) =
D(x)(t)
但是,如果我知道派生词,该如何替换表达式.
But how can I substitute in an expression if, say, I know the derivative.
>> subs(ans,D(x)(t),3)
Error: ()-indexing must appear last in an index expression.
推荐答案
让我们通过一个示例进行工作:
Let's work through an example:
syms t x(t) y
f = x^2+y
dfdt = diff(f,t) % returns 2*D(x)(t)*x(t)
dxdt = diff(x,t) % returns D(x)(t)
subs(dfdt,dxdt,3)
返回6*x(t)
.关键是D(x)(t)
只是相对于时间的导数的印刷表示形式,而不是实际值.您需要将其分配给实际变量.在您的示例中,您需要按照@rayeng的建议进行操作,但是如果您将名称分配给输出,它会更加灵活和清晰.
which returns the 6*x(t)
. The key is that D(x)(t)
is just the printed representation of the derivative with respect to time, not the actual value. You need to assign it to an actual variable. In your example you'd need to do what @rayeng suggests, but it it's much more flexible and clearer if you assign names to your outputs.
x
和dxdt
都是 symfun
的帮助和文档. 调用抽象"或任意"符号函数,即一个没有定义的函数.它们的行为与sym
类型的常规符号变量有些不同.在命令窗口中键入class(x)
或whos
来查看变量类型.
Both x
and dxdt
are what the help and documentation for symfun
call an "abstract" or "arbitrary" symbolic function, i.e., one without a definition. These behave a bit differently from regular symbolic variables of type sym
. Type class(x)
or whos
in your command window to see your variable types.
这篇关于在符号表达式中替换函数的导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!