3
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.