Can't use conv() after using coeffs()? It works when manually inputting the coefficients but doesn't when it is taken using coeffs
4 views (last 30 days)
Show older comments
conv() returns an error when trying to use the outputs of coeffs()
syms s
eq1 = 2*s^2 + 3*s - 1;
N = coeffs(eq1, 'All');
eq2 = s^3 +6*s^2 + 1;
D = coeffs(eq2, 'All');
T = conv(N,D)
^this turns to error while
syms s
eq1 = 2*s^2 + 3*s - 1;
N = [2 3 -1];
eq2 = s^3 +6*s^2 + 1;
D = [1 6 0 1];
T = conv(N,D)
^this properly gives the correct result
0 Comments
Accepted Answer
Walter Roberson
on 14 May 2024
syms s
eq1 = 2*s^2 + 3*s - 1;
N = coeffs(eq1, 'All');
eq2 = s^3 +6*s^2 + 1;
D = coeffs(eq2, 'All');
T = conv( double(N), double(D))
0 Comments
More Answers (1)
Zinea
on 14 May 2024
Reason behind the error:
The issue you are encountering stems from the difference in the types of objects “coeffs” return versus what “conv” expects. The “coeffs” function, when used with symbolic expressions, returns a symbolic array, not a numeric array. The “conv” function, designed for numerical computations, requires numeric arrays or vectors as input.
In the first example, ‘N” and “D” are symbolic arrays because they are the result of “coeffs” applied to symbolic expressions. To use “conv” with the outputs of “coeffs” when dealing with symbolic expressions, these symbolic arrays need to be converted to numeric arrays first. In the second example, “N” and “D” are manually specified as numeric arrays, which is why “conv” works as expected.
Workaround:
If “coeffs” is still needed to be used in the code, the output of “coeffs” must be converted to “double” before being provided as input to "conv,” as is given below:
syms s
eq1 = 2*s^2 + 3*s - 1;
N_sym = coeffs(eq1, 'All');
N = double(N_sym); % Convert a symbolic array to a numeric array.
eq2 = s^3 +6*s^2 + 1;
D_sym = coeffs(eq2, 'All');
D = double(D_sym); % Convert a symbolic array to a numeric array.
T = conv(N, D);
You may refer to the following documentation links for more detail on the “coeffs” and “conv” functions, respectively:
Hope it helps!
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!