How to change from matrix to polynomial using SYM? Mine results in ERROR - Error using symengine (line 59)
7 views (last 30 days)
Show older comments
Here's my code:
% initializing values
D = sym('D');
g1 = [1 0 1 1];
g2 = [1 1 0 1];
g = [g1;g2]; % 4 by 2 matrix, g1 will be transformed to g_D(1) and g2 => g_D(2) as below
[no_of_g, size_of_g] = size(g);
% setting all g_D = 0
for i=1:no_of_g
g_D(i)=0;
end
for i=1:no_of_g
for j=1:size_of_g
g_D(i)=g_D(i)+ g(i,j)*D^(j-1); % expected to have g_D(1)=1+D^2+D^3 but ERROR
end
end
ERROR shows: The following error occurred converting from sym to double: Error using symengine (line 59) DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
Error in test (line 15) g_D(i)=g_D(i)+ g(i,j)*D^(j-1);
0 Comments
Accepted Answer
John D'Errico
on 14 Dec 2015
Edited: John D'Errico
on 14 Dec 2015
Easy enough.
g1 = [1 0 1 1];
syms D
D.^(0:3)*g1.'
ans =
D^3 + D^2 + 1
5 Comments
John D'Errico
on 14 Dec 2015
Edited: John D'Errico
on 14 Dec 2015
p = D.^(0:3)*g1.';
sym2poly(p)
ans =
1 1 0 1
As a test...
p = D.^(0:3)*flip(g1).'
p =
D^3 + D + 1
sym2poly(p)
ans =
1 0 1 1
More Answers (0)
See Also
Categories
Find more on Numbers and Precision 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!