how do i solve invalid data type error?

1 回表示 (過去 30 日間)
Erkut Turkyilmaz
Erkut Turkyilmaz 2020 年 11 月 28 日
回答済み: Aashray 2025 年 2 月 26 日
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 Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by