Reputation: 185
I have an equation: w = (t-x0)*(t-x1)
. I want to solve it with the conv
function(conv((t-x0),(t-x1))
), but its arguments are syms which are t
,x0
and x1
. I get an error that is
Undefined function 'conv2' for input arguments of type 'sym'.
How do I solve its error ? I also want the result to be a polynomial, because I should integrate with polyint
.
For example:
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 ]
Upvotes: 1
Views: 5983
Reputation: 13141
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
gives
[ 1/3, - x0/2 - x1/2, x0*x1, 0]
Update:
It looks OP just wants:
syms t x0 x1;
r=int((t-x0)*(t-x1),t)
gives
t^3/3 + (- x0/2 - x1/2)*t^2 + x0*x1*t
Upvotes: 2
Reputation: 8401
I don't think Matlab yet has a default function for symbolic convolution (although Mr. Moler offers a 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." So we can use straight up multiplication.
>> 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
Note that I flipped the order from coeffs
since the order is the reverse of the poly*
family of functions
Upvotes: 2