Quick Mathematica squib August 14, 2012

I have spent a lot of time manipulating multivariate polynomials in Mathematica, and have been very frustrated at trying to make Coefficient behave the way I think it should. I think Coefficient[2x+3xy, x] should be 2, Mathematica thinks it should be 2+3y. Or rather, I don’t think that this should be the default, but it is very often my desired behavior and I can’t find an option to tell Mathematica that’s what I want.

I just wrote a little snippet to do this for me, and I’m copying it here so I can reuse it in the future:

(* This messy formula describes where inside CoefficientList the term we want is, using the formula that Take[] wants for input. *)

First[Take[L, indexer]]

But this only works if exp is in the range of monomials which Mathematica uses to create CoefficientList. For example, myCoeff[x+2, {x}, {100}] won’t work with the above implementation. You could add a test for that; I don’t know if that would be better in some way.

Just like we have MathOverflow, users of Mathematica have http://mathematica.stackexchange.com/, which is pretty good for this sort of problem. Lots of eager users coming up with nice solutions, and it seems to work much better than the old Mathematica email lists.

Hi Scott! As it happens, I just started looking at mathematica.SE a few days ago; I’ve left 1 question and 2 answers so far. I tend to feel embarrassed to ask for ways to do basic things like this though.

Sorry comments are closed for this entry

search

Secret Blogging Seminar

A group blog by 8 recent Berkeley mathematics Ph.D.'s. Commentary on our own research, other mathematics pursuits, and whatever else we feel like writing about on any given day. Sort of like a seminar, but with (even) more rude commentary from the audience.