# What is the correct syntax for setting up a simulation using a system of ODEs?

sys = {m x''[t] == s ω y'[t] - h (x'[t])^2,
m y''[t] == s ω y'[t] - h (y'[t])^2 - m g,
x'[0] == xdo, x[0] == 0,
y'[0] == ydo, y[0] == 0 };

parms = {m = .0459, s = .1, ω = 100 π, g = 9.8};
ics = {xdo = V Cos[θ], ydo = V Sin[θ], V == 61.69, θ = 12 °};
sol = NDSolve[sys /. parms //. ics, {x[t], y[t]}, {t, 0, 4}];
ParametricPlot[{x[t], y[t]} /. sol, {t, 0, 4}, PlotRange -> All]


I am brand new to Mathematica and have been watching numerous tutorials and still cannot get anywhere. My code simulates a golf ball flight in 2 dimensions. I am not interested in the algebraic solution at all, but rather with the parametric plot. When I enter this code I get numerous errors. I have multiple other variations of these equations that I also need to plot, but I am starting with the simplest of these with no luck at all. I am sure this is not even close to what I need, so I am hoping someone with more experience in Mathematica will lend me some guidance in how to approach this.

• Your parms and ics have to be Rules and you have to provide what h is. You should execute your expressions line by line to see what the output of each is to identify errors early. – Matariki Apr 13 '13 at 22:52
• I also recommend substituting 100. π for 100 π – m_goldberg Apr 13 '13 at 23:08
• And define h ... – Dr. belisarius Apr 13 '13 at 23:14
• You might enjoy this demonstration as well. – cormullion Apr 14 '13 at 7:11
• @Matariki Good idea to evaluate line by line - user6895 should remove the semicolons first, though... – cormullion Apr 14 '13 at 7:13

## 1 Answer

I've made some changes to your code. You can use this as a starting point to make it do what you want. I also set h = 1 since you didn't give a value for it. Note the positions of V and θ.

sys = {m x''[t] == s ω y'[t] - h (x'[t])^2,
m y''[t] == s ω y'[t] - h (y'[t])^2 - m g,
x'[0] == xdo, x[0] == 0,
y'[0] == ydo, y[0] == 0};
parms = {m -> .0459, s -> .1, ω -> 100. π, g -> 9.8, h -> 1.};
ics = {V -> 61.69, θ -> 12 °, xdo -> V Cos[θ], ydo -> V Sin[θ]};
sol = NDSolve[sys /. parms //. ics, {x[t], y[t]}, {t, 0, 4}];
ParametricPlot[{x[t], y[t]} /. sol, {t, 0, 4},
PlotRange -> All]


Now, I don't know if this does what you want, but it doesn't give any errors and produces a graph. Whether it's the correct graph will depend on the actual question which you did not provide.

• When I copy this directly into my notebook I still get numerous errors. I also am curious how you get those arrows that define the constants? I was under the assumption that == would do it? – user6895 Apr 14 '13 at 2:07
• The first error is that the input is not an ordinary differential equation, which I already knew so I am not sure why it says it is. A majority of the other errors state that (a number) cannot be used as a variable. – user6895 Apr 14 '13 at 2:12
• @user6895, what version of MMA are you using? Because it works for me on V9.0.1 – RunnyKine Apr 14 '13 at 2:41
• It says Mathematica 9.0 at the top of my notebook. – user6895 Apr 14 '13 at 2:47
• @user6895 Well, you should post the actual mathematical equations then. Since I don't know what you're trying to achieve, I just tweaked your code to make it work. – RunnyKine Apr 14 '13 at 3:01