0

I have to model a rocket projectile and, although I understand the question, I can't get the code to work in Mathematica.

Here is the question:

A rocket with a unit mass is fired from the ground with a velocity of 100m/s at an angle 60 degrees with the horizontal (hint: use Degree to convert degrees to radians). The rocket experiences a drag so that the equations of motion are: x'' = - a x' and y'' = -g - a y' where a is the drag coefficient. Modify the code from the workshop to solve the new equations; assume g=9.81 and a=0.1. Find the time at which the rocket will hit the ground and then the horizontal distance it will cover until it hits the ground. On a single graph, plot the trajectory of the rocket (hint: use Solve and ignore any warnings) for a selection of values of a; label the axes and plots.

My coding attempt:

(* Exercise 4 *)
ClearAll["Global`*"]
(*g=gravity; a=drag; vx=Initial Horiz.Velocity; vy=Initial Vert.Velocity*)
g = 9.81; a = 0.1; vx = 100/Tan[Pi/3]; vy = 100;
solution = DSolve[{x''[t] == -a*x'[t], y''[t] == -g - a*y'[t], x'[0] == vx, y'[0] == vy, x[0] == 0, y[0] == 0}, {x[t], y[t]}, t];
horiz[t_] = Evaluate[x[t] /. solution[[1]]];
vert[t_] = Evaluate[y[t] /. solution[[1]]];
ParametricPlot[{horiz[t], vert[t]}, {t, 0, 100}, PlotRange -> {0, 100}]

Help would be much appreciated.

  • If I copy that code into a new notebook it runs perfectly fine. Can you describe what exactly your problem is? – AndreasP Oct 18 '16 at 12:43
  • Here is what I get - https://postimg.org/image/ifv00b6r3/ – Scott Davidson Oct 18 '16 at 12:46
  • I'm afraid I can't help you since I don't have access to Mathematica 9. Maybe add the Version you're using to the question since in M11 it works. – AndreasP Oct 18 '16 at 12:49
  • Have you tried quitting the kernel? – Feyre Oct 18 '16 at 12:49
  • ...it is now working. I forgot Rule 1 - if it doesn't work then switch it off and switch it back on again! Why was that happening though? – Scott Davidson Oct 18 '16 at 12:51
  • Typically this happens when you mistakenly use a single = in NDSolve, which assigns the right hand side to the left. When you correct it to the double == for equality, it is now True. Short of restarting the kernel, you can Clear the left hand side. – Chris K Oct 18 '16 at 14:39

0 Answers0