I have a list, obtained after differentiating a list of expressions, which contains zeros and symbols, say:
A = {x1^2, x2^2, x3^2, x4^2}
D[A,x3]
results in the list:
{0, 0, 2 x3, 0}
How do I get the position of the non-zero entry, mathematica cannot compare symbols to zero directly. I could convert the elements of the list to strings but is there a faster way?
===vs==. Posting your code is also a good idea. – Yves Klett May 03 '14 at 09:37Position[D[A, x3], x_ /; ! TrueQ[x == 0], {1}, Heads -> False]– Kuba May 03 '14 at 09:41Position[D[A, x3], Except[0], 1, Heads -> False]– Dr. belisarius May 03 '14 at 09:55ArrayRules[D[A, x3]][[;; -2, 1, 1]]– Dr. belisarius May 03 '14 at 09:59Condition. Also closely related: 46852 =>SparseArray[list]["NonzeroPositions"]– Kuba May 03 '14 at 10:33