1

How to expand taylor series/polynomials about Q=0 , and then extract coefficients as a list

example :

taylor ( (sin(q)), q, 0, 9); //taylor expansion for first 9 terms gives the next line

(%o1)/T/    q\-q^3/6+q^5/120\-q^7/5040+q^9/362880+...

then using coeff ((%o1), q ^n); gives me the coefficient at n only, what i want is a list for all the coefficients of that expression

webprogrammer
  • 2,393
  • 3
  • 21
  • 27
Mk47
  • 13
  • 1
  • 4

2 Answers2

1

Try coeff plus makelist, e.g. something like: makelist(coeff(%o1, q, n), n, 0, 9);

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
0

Edit:

I see now that I misread your question and there is already an answer. Nevertheless I will keep it because it is related to your question.


Use powerseries instead of taylor:

(%i1) expr:powerseries(sin(x),x,0);
                           inf
                           ====        i2  2 i2 + 1
                           \      (- 1)   x
(%o1)                       >     -----------------
                           /         (2 i2 + 1)!
                           ====
                           i2 = 0

You can access the coefficient by the args or part function

(%i2) op(expr);
(%o2)                                 sum
(%i3) args(expr);
                              i2  2 i2 + 1
                         (- 1)   x
(%o3)                   [-----------------, i2, 0, inf]
                            (2 i2 + 1)!
(%i4) part(expr,1);
                                    i2  2 i2 + 1
                               (- 1)   x
(%o4)                          -----------------
                                  (2 i2 + 1)!
(%i5) args(expr)[1];
                                    i2  2 i2 + 1
                               (- 1)   x
(%o5)                          -----------------
                                  (2 i2 + 1)!

If you want to change the index variable:

(%i6) niceindices(expr),niceindicespref=[n];
                             inf
                             ====       n  2 n + 1
                             \     (- 1)  x
(%o6)                        >    ---------------
                             /       (2 n + 1)!
                             ====
                             n = 0
miracle173
  • 1,852
  • 16
  • 33