1

I'm attempting to repeatedly perform a simple algorithm with incremental changes of a parameter.

I can easily express my changing parameter:

Do[a[n] = (10/180*Pi + n/180*Pi);
Print[a[n]], {n, 0, 70, 1}];

Here is what I wish to do for each iteration:

sol = 
NDSolve[{y''[t] == -10 - 0.3*(Sin[a]), 
y'[0] == 12*Sin[a], y[0] == 0}, y[t], t];
h[t_]=y[t]/.sol;

FindMaximum[h[t],{t,2}]

I think I need to define sol[n_] and incorporate it into a Table function:

sol[n_]= ??
sol2[n_]=FindMaximum[sol[n],{t,2}]    
m = Table[{a[n], sol2[n]}, {n, (Pi*10/180), (Pi*80/
180, Pi/180}];

But this is where I've been stuck for a while. Even a greatly simplified example would be very helpful.

xaxXos
  • 77
  • 1
  • 7

2 Answers2

4

Whenever you can, you should be using Map[] instead of tables:

k =FindMaximum[y@t/.NDSolve[{y''[t] == -10 - 3/10  Sin@#, y'[0] == 12 Sin@#, y[0] == 0},
                            y[t], {t, 0, 2 Pi}], {t, 2}]  & /@ (Pi/180 Range[10, 80])

Now, plotting the max vs t:

ListPlot[{t /. #[[2]], #[[1]]} & /@ k]

Mathematica graphics

Now, the max vs n:

ListPlot[k[[All, 1]]]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
3

Create a list of the changing parameter:

a = Pi/180 * Range[10,80]

Now for the NDSolve

 sol = Table[NDSolve[{y''[t] == -10 - 0.3 Sin[a[[i]]], y'[0] == 12 Sin[a[[i]]], 
    y[0] == 0}, y[t], t], {i, 1, Length[a]}] // Flatten

You'll then get the solutions as a list.

RunnyKine
  • 33,088
  • 3
  • 109
  • 176