0
$\begingroup$

I want to extract coefficients of a linear formula and I wrote the following function. But it didn't work.

f = Subscript[x, 1] + Times[2, Subscript[x, 2]]
extractCoeff[f_] := Table[If[Head[f[[i]]] == Times, f[[i, 1]], 1], {i, Length[f]}]

What should I do?
Please tell me.

$\endgroup$
2
  • 2
    $\begingroup$ Use SameQ (===); Equal (==) is not intended for the comparison you want to do. $\endgroup$ Commented Oct 2, 2018 at 11:15
  • $\begingroup$ Thank you very much, J. M. is somewhat okay. I changed my code, my code is OK now. $\endgroup$
    – tchappy ha
    Commented Oct 2, 2018 at 11:16

0

Browse other questions tagged or ask your own question.