在符号表达式中替换函数的导数 [英] substitute the derivative of a function in a symbolic expression

查看:117
本文介绍了在符号表达式中替换函数的导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与在Matlab中,函数的导数可以用符号表示为

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.

xdxdt都是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆