3

I'm rather new to Mathematica so I would greatly appreciate any help. I want to find the series expansion coefficients of iterations of a function and export them as a .csv. Here is what I have written so far:

f[x_] := Sin[x]
iterations = 10;
myOrder=11;
Coeff=ConstantArray[0,{iterations,myOrder}];
For[i=0,i<iterations,i++,
For[j=0,j<myOrder,j++,
Coeff[[i,j]]=Coefficient[Normal[Series[Nest[f,x,i],{x,j,j+1}]],x,j]]]
Export["Coefficient.csv",Coeff];

When I run this, I receive the following errors after the for loops:

Set::partd1: Depth of object Coeff[[i,j]] is not sufficient for the given part specification.
General::stop: Further output of Set::partd1 will be suppressed during this calculation.

Is there an easier way to make what I am trying to make? I'm sure i and j are in bounds in terms of the depth of the array (I have enough array elements to satisfy the for loops).

Thank you for your help.

1 Answers1

3

Perhaps this?:

funcs = Rest@NestList[Sin, x, 10];

coeff = Table[ SeriesCoefficient[Series[f, {x, 0, 11}], k], {f, funcs}, {k, 0, 10}];

coeff // Column

See Why should I avoid the For loop in Mathematica? for alternatives for for loops.

Michael E2
  • 235,386
  • 17
  • 334
  • 747