# Extracting Coefficients from a List of Sines

I want to extract the coefficients from the following list:

list={16.2219 Sin[16.2219 t], 6.60924 Sin[6.60924 t], 13.927 Sin[
13.927 t], 2.91309 Sin[2.91309 t]}


The only way I've found it to work is if I put the exact expression for Sin in the following manner,

Coefficient[list[], Sin[16.2219]]


My actual list is very long and each Sin has a different argument. In a perfect world I would like to do,

coefs = Table[Coefficient[list[[i]],Sin[t]],{i,1,Length[list]}]


Anyone have experience with this? Thanks!

• Iterate over Variables[list]. – Daniel Lichtblau Oct 16 '14 at 17:50
• Coefficient[#, #2] & @@@ Thread@{list, Variables /@ list}: i.stack.imgur.com/1zlFL.png – Öskå Oct 16 '14 at 17:51

A fairly general approach is to use pattern matching, but always look at the FullForm of mathematical expressions before you write your patterns or you may be surprised.

Cases[list, x_*_Sin :> x]

{16.2219, 6.60924, 13.927, 2.91309}


For the particular case you can also use:

list /. _Sin -> 1

{16.2219, 6.60924, 13.927, 2.91309}


Or simply extract the parts you want (which rhermans already showed):

First /@ list

{16.2219, 6.60924, 13.927, 2.91309}


This might not be the standard solution, but anyways. If all elements have exactly the form $a\sin(at)$ with $a>0$, you could do

Sqrt[D[list, t] /. t -> 0]

{16.2219, 6.60924, 13.927, 2.91309}


since $D(a\sin(at))=a^2\cos(at)$ which equals $a^2$ for $t=0$.

• I gladly admit that the other solution(s) proposed is better than this. What is the standard then, should I delete it? – mickep Oct 16 '14 at 17:55
• welcome to Mathematica.SE. I suggest you keep the answer. It is an interesting outside-the-box approach. (+1) – kglr Oct 16 '14 at 18:03
• @kguler Thank you very much for your kind comment and information. – mickep Oct 16 '14 at 18:59
#[] & /@ list


also known as

First /@ list


(as pointed bt @Mr.Wizard).

Or (credit to @DanielLichtblau)

First@(#/Variables[#]) & /@ list

{16.2219, 6.60924, 13.927, 2.91309}

• FYI: #[] & /@ list would be better written as list[[All, 1]]. +1 nevertheless – Mr.Wizard Oct 16 '14 at 18:06

If you need to use Coefficient you can do

Coefficient[list /. Sin[_] :> z, z]
(* {16.2219,6.60924,13.927,2.91309} *)


If not, many alternatives, including

list /. Sin -> (1 &)
(* {16.2219,6.60924,13.927,2.91309} *)


you can also try these:

list /. Sin[__] :> Sin[\[Pi]/2]

Level[list, {2}][[1 ;; -1 ;; 2]]

DeleteCases[list, Sin[__], -1]

Replace[list, _ -> \[Pi]/2, {3}]

(*{16.2219, 6.60924, 13.927, 2.91309}*)