我可以在MATLAB中更改符号函数的公式吗? [英] Can I change the formula of a symbolic function in MATLAB?
问题描述
我有以下代码:
syms t x;
e=symfun(x-t,[x,t]);
在这个问题中,我想解决x是t的函数,但我只知道给定t的值,因此在这里将其建模为变量.我想针对时间区分e而不丢失" x ,这样我就可以用我所知道的x'(t)代替它. 在我的另一个问题中,有人建议我写以下内容:
In the problem I want to solve x is a function of t but I only know its value at the given t,so I modeled it here as a variable.I want to differentiate e with respect to time without "losing" x,so that I can then substitute it with x'(t) which is known to me. In another question of mine here,someone suggested that I write the following:
e=symfun(exp(t)-t,[t]);
然后进行微分检查,是否可以将exp(t)替换为x'(t)的值.
and after the differentiation check if I can substitute exp(t) with the value of x'(t).
这可能吗?还有其他更整洁的方式吗?
Is this possible?Is there any other neater way?
推荐答案
I'm really not sure I understand what you're asking (and I didn't understand your other question either), but here's an attempt.
由于x
是时间的函数,因此,通过使其成为 symfun
调用抽象"或任意"符号函数,即没有定义的符号函数.在Matlab R2014b中:
Since, x
is a function of time, let's make that explicit by making it what the help and documentation for symfun
calls an "abstract" or "arbitrary" symbolic function, i.e., one without a definition. In Matlab R2014b:
syms t x(t);
e = symfun(x-t,t)
返回
e(t) =
x(t) - t
采用symfun
函数e
的时间导数:
edot = diff(e,t)
返回
edot(t) =
D(x)(t) - 1
edot(t)
的表达式是x
的时间导数的函数:
the expression for edot(t)
is a function of the derivative of x
with respect to time:
xdot = diff(x,t)
这是抽象的symfun
:
xdot(t) =
D(x)(t)
现在,我想您希望能够将xdot
(xdot_given
)的特定值替换为t_given
处的t
的e(t)
.您应该只使用 subs
即可执行此操作像这样:
Now, I think you want to be able to substitute a specific value for xdot
(xdot_given
) into e(t)
for t
at t_given
. You should be able to do this just using subs
, e.g., something like this:
sums t_given xdot_given;
edot_t_given = subs(edot,{t,xdot},{t_given, xdot_given});
如果edot
的唯一随时间变化的部分是xdot
部分,则可能无需替换t
.
You may not need to substitute t
if the only parts of edot
that are a function of time are the xdot
parts.
这篇关于我可以在MATLAB中更改符号函数的公式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!