Find the coefficient of a certain term in an expression

6 views (last 30 days)
Suppose I have:
syms X Y Z
A = 1.123 * X^3 + 4.234 * X * Y * Z + 5.32 * X^2 *Y
Is there a way to obtain the exact coefficient of, let's say:
X^2 * Y
from A automatically (usually I will have a much larger polynomial expression)?
In my application, I will have a large homogenous polynomial A. Eventually, I will choose a i, j and k, defining the trinomial:
,
and then I will have to obtain the corresponding coefficient
A_ijk
that is multiplying:
X^i * Y^j * Z^k
.
  3 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Sep 2020
Not directly, no.
However, you can coeffs(A,X, 'all') and look in the third last entry (highest degree is first so third last is degree 2). The result would be a summation of terms (for example it might be 5.32 * Y + 7 if the expression included 5.32*X^2*Y + 7*X^2 ) .
You can then coeffs() that entry for Y and pull out all but the constant term.

Tags

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!