how do i solve invalid data type error?

1 次查看(过去 30 天)
Hi everyone, i just created a partial function by using piecewise function, and further i wanted to convolute the function with itself and i get the invalid data type error when i do that.I get that i have to convert symbolic function to some numeric argument and i've tried some functions such as sym2cell but it didnt work out.This is the error:
Error using conv2
Invalid data type. First and second arguments must be numeric or logical.
And here is my code below:
a = 10;
b = 4;
syms t;
r = piecewise(a<t<(a+b),(a+b));
y = conv(r,r);

回答(1 个)

Aashray
Aashray 2025-2-26
Hello Erkut,
The issue you're encountering is because “conv()” function in MATLAB is intended for numerical arrays, not symbolic expressions. And the variable “r” which holds the piecewise function is a symbolic expression.
As far as I know, MATLAB does not directly support convolution for symbolic expressions. So, you will have to perform the convolution manually following the convolution expression:
You may refer to below code for better understanding:
syms t tau;
a = 10;
b = 4;
r = piecewise(a < t < (a + b), (a + b), 0);
% Perform symbolic convolution
conv_result = int(r * subs(r, t, t - tau), tau, -inf, inf);
disp(conv_result);
Also attaching the documentations of symbolic substitute “subs()” and integration “int()” functions for reference:

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by