Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
You might find this useful: mathematica.stackexchange.com/q/7924/8 – Verbeia Feb 6 '13 at 4:46

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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