Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.4K Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Ask for help: How to get the coefficients of polynomial of sin(n*x)

Posted 10 years ago

I want to get the coefficients of the polynomial 1+2sin(2x)+3sin(3x)+4sin(4x) as {1,2,3,4}.

But I use this code

Coefficient[1+2sin(2x)+3sin(3x)+4sin(4x), Table[f[i*x], {i, 3}]]

Only get the {2,3,4}, can not get the coefficient of constant term.

How to get what I want?

POSTED BY: xiao bai
6 Replies

The following works on your example:

sinList = {Sin[2 x], Sin[3 x], Sin[4 x]};
f = 1 + 2 Sin[2 x] + 3 Sin[3 x] + 4 Sin[4 x];
Prepend[Map[Coefficient[f, #] &, sinList], f /. Thread[sinList -> 0]]
POSTED BY: Gianluca Gorni
Posted 10 years ago

It does work! Many thanks for your helpful.

POSTED BY: xiao bai

I want to get the coefficients of the belw polynomial 1+2sin(2x)+3sin(3x)+4sin(4x) as {1,2,3,4}.

But the above is not a polynomial? If you want to get {1,2,3,4} you can try

Clear[x];
f = 1 + 2 Sin[2 x] + 3 Sin[3 x] + 4 Sin[4 x];
f = List @@ f;
f /. Sin[_] -> Sequence @@ {}
(*{1, 2, 3, 4}*)
POSTED BY: Nasser M. Abbasi
Posted 10 years ago

Thank you very much for your help!

But some bugs appears:

If the input series is "0 + 0 Sin[2 x] + 0 Sin[3 x] + 4 Sin[4 x];"

Only get the result {4}. But I want to get {0,0,0,4} Could you please give more advice?

POSTED BY: xiao bai

If the input series is "0 + 0 Sin[2 x] + 0 Sin[3 x] + 4 Sin[4 x];" Only get the result {4}

There is no bug. Mathematica input itself simplifies 0 Sin[2 x] + 0 Sin[3 x] to zero before even the evaluator gets hold of the expression; So if you type

  f = 0 + 0 Sin[2 x] + 0 Sin[3 x] + 4 Sin[4 x]

and look at f you'll see it is 4 Sin[4 x]

There is nothing you can do about this really, unless you use Hold and friends when you actually type the expression itself.

      f = Hold[0 + 0 Sin[2 x] + 0 Sin[3 x] + 4 Sin[4 x]]

But once you release the Hold, we are back to square one. May be you can try using Strings. But I am not sure what you are trying to do there.

POSTED BY: Nasser M. Abbasi
Posted 10 years ago

Sorry for not clarifying the problem.

I want extract the coefficients of sine/cosine series and transform them into matrix, so I need coefficients of all terms (including the 0 terms).

"String" does not work, but thank you all the same.

POSTED BY: xiao bai
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard