我正在使用 MATLAB 的符号工具箱,但在提取导数系数时遇到了一些问题。也许 MATLAB 不能做我正在寻找的东西。无论如何,重现我遇到的问题的代码如下所示:
clear ; close all; clc;
syms a b t
x = sym('x(t)');
y = sym('y(t)');
syms a b;
ra = a*cos(x);
radot = diff(ra, t);
xdot = diff(x,t);
ydot = diff(y,t);
% This one works as expected
works = coeffs(radot(1), xdot)
% This doesn't work as expected
fails = coeffs(radot(1), ydot)
上述代码部分中的注释突出显示了哪些有效,哪些不按预期工作。具体来说,输出是:
radot =
-a*sin(x(t))*diff(x(t), t)
works =
-a*sin(x(t))
fails =
-a*sin(x(t))*diff(x(t), t)
有谁知道为什么会发生这种情况或我是否做错了什么?