In my work, i usually come across expressions of the form: $$\text{L3}=\frac{625 f_5^{30} q^4}{f_1^{31}}+\frac{24458 f_5^{24} q^3}{f_1^{25}}+\frac{25436 f_5^{18} q^2}{f_1^{19}}+\frac{25415 f_5^{12} q}{f_1^{13}}+\frac{125 f_5^6}{f_1^7}.$$ I would like to extract only numeric coefficients of the above expression L3 i.e., i should get {625,24458,25436,25415,125} as a list in Mathematica. If we use CoefficientList[], we get all the coefficients along with f_i's as well. Tried with ChatGPT another command: coefficients=Cases[L3,_?NumericQ,Infinity], but this also not working as this gives subscripts and superscripts of $f_i$'s in list How can i get only numeric coefficients in Mathematica?
L3=(125 Subsuperscript[f, 5, 6])/Subsuperscript[f, 1, 7]+(25415 q Subsuperscript[f, 5, 12])/Subsuperscript[f, 1, 13]+(25436 q^2 Subsuperscript[f, 5, 18])/Subsuperscript[f, 1, 19]+(24458 q^3 Subsuperscript[f, 5, 24])/Subsuperscript[f, 1, 25]+(625 q^4 Subsuperscript[f, 5, 30])/Subsuperscript[f, 1, 31] CoefficientList[L3,q] coefficients=Cases[L3,_?NumericQ,Infinity] Any other way to get only numeric coefficients when we have a polynomial containing variable coefficients as well.
CoefficientList[L3, q] /. _Subsuperscript -> 1$\endgroup$data = Cases[L3, c_?NumericQ*v_ :> v -> c]; Values[data]? The point ofdatais thatPlusisOrderless, and you might need to know which coefficient goes with which term. $\endgroup$