# Discrete Fourier Transform of NDsolve in Mathematica?

1. Jan 5, 2012

### Catrin

I want to do a discrete fourier transform of the solution I have found using NDSolve, however, because the NDSolve creates Interpolating functions rather than numbers I can't do this. Any help is appreciated. I've attatched the file I'm working with.

Catrin

File size:
19.3 KB
Views:
121
2. Jan 5, 2012

### Bill Simpson

Use the InterpolatingFunction to create a Table of equally spaced points and then do Fourier on the table?

3. Jan 5, 2012

### Catrin

That's what I tried, but I just get a table of interpolating functions.

4. Jan 5, 2012

### Bill Simpson

It is sometimes "less than obvious" how to correctly use an InterpolatingFunction.

In[1]:=eq1 = {D[a[t], {t, 2}] + 0.22 (a[t])^2 + a[t]==0, a[0]==2, a'[0]==0}

Out[1]={a[t]+0.22a[t]^2+a''[t]==0,a[0]==2,a'[0]==0}

In[2]:= timesol01=NDSolve[eq1,a, {t,0,200}];

In[3]:=Table[First[a[t]/.timesol01],{t,0,200}]

Out[3]=
{2.,0.759429,-1.40946,-2.76245,-3.0405,-2.28904,-0.466852,1.58763,1.71456,-0.\
252706,-2.15986,-3.01434,-2.83345,-1.58573,0.552881,1.98694,0.957919,-1.22436,\
-2.6816,-3.05752,-2.40789,-0.677208,1.44126,1.82006,-0.0364096,-2.02039,-2.\
97895,-2.89475,-1.75264,0.340689,1.94796,1.14587,-1.03115,-2.59077,-3.06543,-\
2.51646,-0.882344,1.27765,1.90243,0.180197,-1.87073,-2.93423,-2.9465,-1.90977,\
0.125161,1.88374,1.32079,-0.830714,-2.48981,-3.06428,-2.61483,-1.08103,1.\
09918,1.96031,0.395086,-1.71108,-2.88007,-2.98884,-2.05685,-0.0915471,1.79535,\
1.48022,-0.62413,-2.37863,-3.05405,-2.70311,-1.27225,0.908322,1.99273,0.\
606058,-1.54176,-2.81631,-3.02187,-2.1937,-0.307455,1.68423,1.62185,-0.412673,\
-2.25715,-3.03472,-2.78143,-1.45516,0.707557,1.99915,0.81078,-1.36319,-2.\
74282,-3.04569,-2.32024,-0.520773,1.55216,1.7435,-0.197828,-2.12536,-3.00622,-\
2.84995,-1.62909,0.499359,1.97946,1.00682,-1.17596,-2.65945,-3.06039,-2.43647,\
-0.729919,1.40119,1.84326,0.0187196,-1.98329,-2.96847,-2.90881,-1.79353,0.\
286117,1.93399,1.19168,-0.980831,-2.56606,-3.066,-2.54244,-0.933512,1.23359,1.\
91951,0.235077,-1.83108,-2.92136,-2.95815,-1.94812,0.0701023,1.86351,1.36288,-\
0.778733,-2.46252,-3.06254,-2.63822,-1.13038,1.05175,1.97099,0.449173,-1.\
66895,-2.86477,-2.99811,-2.0926,-0.146573,1.76919,1.518,-0.570791,-2.34873,-3.\
05,-2.72395,-1.31955,0.858138,1.99684,0.658774,-1.49723,-2.79856,-3.02879,-2.\
22683,-0.361975,1.65257,1.65473,-0.358335,-2.22464,-3.02835,-2.79977,-1.50022,\
0.655263,1.99662,0.861512,-1.3164,-2.72258,-3.05029,-2.35075,-0.574364,1.\
51551,1.77098,-0.142899,-2.09023,-2.99751,-2.86581,-1.67178,0.445571,1.97033,\
1.05494,-1.1271,-2.63668,-3.06267,-2.46436,-0.782212,1.3601,1.86491,0.0737764,\
-1.94558,-2.95739,-2.92224,-1.83374,0.231426,1.91842,1.23655,-0.930117,-2.\
54072,-3.06598}

In[4]:= Plot[Evaluate[First[a[t]/.timesol01]],{t,0, 4*Pi}]

Out[4]=<<<plot snipped>>>

5. Jan 8, 2012

### Catrin

Thank you, that really helped.