-2

Let say that we have the polynomial f=a^2*b+b^2*c+c*d.

I would like to know if, in Matlab, I could find all the terms of f that contain specific polynomials of variables a, b, c and d.

For example, if I have a polynomial of variable c, that is g=b, then I want to find out the terms: a^2+b*c.

If I have a polynomial of variable b, that is g=c, then I want to find out the terms: b^2+d.

It is like to take a common factor (polynomial of a variable) and then to find the terms that contains this factor.

I know that I can use factor(), but I have polynomials in which the usage of factor() does not work, because they cannot be written as a product of polynomials.

Vassilis Chasiotis
  • 427
  • 1
  • 3
  • 15

1 Answers1

0

Your question is confusingly worded. As far as I can tell, you have a polynomial in several variables, and want to reduce the power on all of a given variable by 1, and remove the terms which are constant with respect to that variable. Here is a way to do that:

syms a b c d
f=a^2*b+b^2*c+c*d

[p,q] = coeffs(f,c)
% p = [ b^2 + d, a^2*b]
% q = [ c, 1]

sum(p(1:end-1).*q(2:end))

coeffs returns the coefficients of the various powers of c in the expression f, returning the coefficients in p and the powers of c in q. Then multiply the i-th entry of p by the I+1-th entry of q and add them up.

David
  • 8,449
  • 1
  • 22
  • 32