1
$\begingroup$

I'd like to write a function that returns the coefficient of a polynomial, but excludes some 'cross-term' coefficients.

The function could be called CoefficientExclude, and the first argument would take a variable, then the second argument would be a list of variables to exclude.

So for p defined as p=a1*x1 + a2*x1/y1+a2*y1, this function would return:

CoefficientExclude[p,{x1},{y1}] = a1

CoefficientExclude[p,{y1},{x1}] = a2

CoefficientExclude[p,{x1/y1},{}] = a2

$\endgroup$

1 Answer 1

1
$\begingroup$

I think you need SeriesCoefficient.

For example

p = a1*x1 + a2*x1/y1 + a2*y1
SeriesCoefficient[p, {x1, 0, n}, {y1, 0, m}]

gives

$\begin{cases} \text{a2} & (m=-1 \&\& n=1) || (m=1 \&\& n=0) \\ 0 & (m\neq -1 \&\& m\neq 0) || n\neq 1 \\ \text{a1} & \text{True} \end{cases}$

For a cross term both m and n will be nonzero. Avoid that condition and you are done.

In your case [...,{x1^c},{y1}] is equivalent to m=c and n=0

SeriesCoefficient[p, {x1, 0, 1}, {y1, 0, 0}]

Or say you explicitly want the coefficient of x1/y1, (m=1,n=-1)

SeriesCoefficient[p, {x1, 0, 1}, {y1, 0, -1}]
$\endgroup$
1
  • $\begingroup$ of course, thanks! $\endgroup$
    – science404
    Commented Apr 24, 2015 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.