how do i solve invalid data type error?

1 visualizzazione (ultimi 30 giorni)
Erkut Turkyilmaz
Erkut Turkyilmaz il 28 Nov 2020
Risposto: Aashray il 26 Feb 2025
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);

Risposte (1)

Aashray
Aashray il 26 Feb 2025
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:

Community Treasure Hunt

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

Start Hunting!

Translated by