Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

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.