Symbolic expression not recognized as polynomial
Show older comments
I needed to construct a symbolic series which was in the form of a summation and did so by computing the components of the series in a loop, adding them to a symbolic array and then using sum function. Finally the process involved substituting another symbolic expression in the polynomial. Now I need to extract all coefficients of the symbolic expression thus obtained. However, when I try sym2poly, I get error
Error using sym/sym2poly (line 26)
Not a polynomial.
Similarly for coeff, it gives
Error using symengine (line 58)
Expression is not a polynomial.
Error in sym/coeffs (line 38)
cSym = mupadmex('symobj::coeffs',p.s, args{:});
It is being recognized as expression when I use symvar as it correctly gives the variable used. The order is polynomial if 17, hence I cannot manually copy all coefficients from expression.
EDIT: In response to Walter Roberson: I did not use series function. I used a loop and then sum. Something like this:
t=sym(zeros(1,(((N-1)/2)+1)));
syms x;
for m=1:(((N-1)/2)+1)
t(m)= (some mathematical expression)
end
k=sum(t);
s=(some symbolic expression);
Kx=subs(k,s);
I had a doubt that this maybe because of the substitution that it is treated as a symbol instead of expression, but is there any way to resolve this problem and get the coefficients?
Answers (1)
Walter Roberson
on 8 Jan 2016
Please show the code that generates the expression.
If you used series() or taylor() in constructing the expression then it is not a polynomial -- besides the visible presence of an order term, the internal representation of series and taylor are not polynomials.
For example,
CP = sym('v -> coerce(v,DOM_POLY)');
then call CP on your expression
6 Comments
Abhinav Dhere
on 8 Jan 2016
Walter Roberson
on 8 Jan 2016
What are you substituting?
"subs(s,new) returns a copy of s replacing all occurrences of the default variable in s with new, and then evaluating s. The default variable is defined by symvar."
That is always risky as you do not know which of your variables might possibly have canceled out, leaving a different variable as the default variable. And the order for symvar is a bit wonky. I recommend always specifying the variable to be substituted explicitly, even if you only expect one variable to exist. For example,
kx = subs(k, t, s);
Abhinav Dhere
on 8 Jan 2016
Walter Roberson
on 8 Jan 2016
Hmmm... Try
OP0 = sym('v->op(v,0);')
and then show
OP0(k)
I would also suggest recoding as
k = sym(0);
syms x;
for m=1:(((N-1)/2)+1)
k = k + (some mathematical expression)
end
with no sum(k). This avoids running into issues with the difference between symsum() and sum applied to a vector that happens to be symbolic; I have seen cases where symsum() turns into sum() with a symbolic argument behind the scenes which could be a problem if it is happening.
Abhinav Dhere
on 8 Jan 2016
Walter Roberson
on 8 Jan 2016
What does the OP0(Kx) show, and was it different than OP0(k) ?
Did the coerce work?
Categories
Find more on Linear Algebra 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!