Coefficient
Usage Message: Coefficient[expr, form] gives the coefficient of form in the polynomial expr. Coefficient[expr, form,
n] gives the coefficient of form^n in expr. Attributes[Coefficient] = {Listable, Protected}
Options: Modulus
-> 0 Trig
-> False Notes: Coefficient is in most cases mathematically ambiguous if the the second
argument is a sum, product, or power. If Coefficient does not do what you want in these cases, it is normally possible to get desired results using
pattern matching, in conjunction with functions such as Cases
. There is an error in the Coefficient function in Version 3.0 of Mathematica that will cause it to crash or return incorrect results for
certain examples in which the second argument is not a symbol. Equivalent functionality can always be achieved in other ways, such as by substituting a symbol in
place of the non-symbol second argument, or by using patterns. Here is a redefinition of Coefficient using patterns, and the Cases
function:
Unprotect[Coefficient]
Coefficient[p_Plus, q_] := Plus @@ Cases[p, z_. q -> z] /; Head[q] =!= Symbol
Coefficient[p_, q_] := Plus @@ Cases[{p}, z_. q -> z] /; Head[q] =!= Symbol
Protect[Coefficient]
After entering this change, you should see the following behavior for these examples (which would otherwise crash):
In[5]:= Coefficient[b x/y, x/y]
Out[5]= b
In[6]:= Coefficient[1 + b x/y + c x/y, x/y]
Out[6]= b + c
You can have this workaround automatically loaded by placing
http://support.wolfram.com/mathematica/kernel/Symbols/System/Coefficient.m
at the location given by
In[7]:= ToFileName[{$TopDirectory,"AddOns", "Autoload",
"Coefficient", "Kernel"}, "init.m"]
For questions or comments about this behavior, please contact Technical Support. We apologize for any difficultes caused by this error.
Additional Online Documentation:
Mathematica 3.0
http://documents.wolfram.com/v3/RefGuide/Coefficient.html
Mathematica 4.0
http://documents.wolfram.com/v4/RefGuide/Coefficient.html
Questions or comments? Send email to support@wolfram.com.
| |