在带有 syms 参数的 Matlab conv 中

In Matlab conv with syms argument

我有一个等式:w = (t-x0)*(t-x1)。我想用 conv 函数(conv((t-x0),(t-x1)))来解决它,但它的参数是符号,即 tx0x1。我收到一个错误

Undefined function 'conv2' for input arguments of type 'sym'.

如何解决它的错误?我还希望结果是多项式,因为我应该与 polyint.

整合

例如:

w = (t-x0)*(t-x1) --> w = t^2 - t*(x0+x1) + x0*x1 --> w=[ 1   -x0-x1   x0*x1 ]

polyint(w) -->  w= t^3/3 -t^2/2*(x0+x1) + t*x0*x1 --> w=[ 1/3  -1/2*(x0+x1)  x0*x1  0 ]

我认为 Matlab 还没有符号卷积的默认函数(虽然 Mr. Moler 提供了一个 shim here), but that's not a big deal in this instance since as it is mentioned:"If [the inputs] are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials." 所以我们可以直接使用乘法。

>> syms t x0 x1
>> w = (t-x0)*(t-x1);
>> p = fliplr(coeffs(w,t))
    p =
    [ 1, - x0 - x1, x0*x1]
>> pint = polyint(p)
    pint =
    [ 1/3, - x0/2 - x1/2, x0*x1, 0]
>> wint = poly2sym(pint,t)
    wint =
    t^3/3 + (- x0/2 - x1/2)*t^2 + x0*x1*t

请注意,我颠倒了 coeffs 的顺序,因为顺序与 poly* 函数族相反

clear
syms t x0 x1;
r = int((t-x0)*(t-x1),t);
c = evalin(symengine,sprintf('coeff(%s, t)',char(r)));
c0= evalin(symengine,sprintf('coeff(%s, t,0)',char(r)));
if c0==0
   c=[c 0];
end

给予

  [ 1/3, - x0/2 - x1/2, x0*x1, 0]

更新:

看来OP只是想要:

syms t x0 x1;
r=int((t-x0)*(t-x1),t)

给予

t^3/3 + (- x0/2 - x1/2)*t^2 + x0*x1*t