# Trying to graph trajectory function in Mathematica? Won't Graph?

The exercise is:

Define the trajectory function y(x) in Mathematica. Pick the initial speed (in meters per second) equal to 2 and the angle equal to 30 degrees. Plot this function from x=0 to x=0.5.

I approached this problem by typing

y[x_] := x*Tan[θ] - ((9.8*x^2)/(2*v^2*(.5 + (.5*Cos[2 θ]))))


I then assigned θ and initial speed:

 θ==30

v==2


and then wrote the plot function:

Plot[y, {x,0,0/5}]


AND THEN GOT AN EMPTY GRAPH! HELP!

-
== is not assignment. Also, use y[x] in Plot not y alone. It seems that you know / is division so why you set .5 as 0/5 in Plot? – Kuba Jan 11 '14 at 23:53
Also you need to write 30 Degree because Cos[theta] works with radians. Degree will convert your value to radians. Kuba forgot to say what IS assignment, = is used for assignment to variables. – Pickett Jan 11 '14 at 23:57

θ = π/6;  (* changed 30 degres to radians         *)
v = 2;    (* replace == by =. ":=" would do too   *)
y[x_] := x Tan[θ] - ((9.8 x^2)/(2 v^2 (.5 + (.5 Cos[2 θ]))))
(* "*"'s are OK but not required        *)
Plot[ y[x], {x, 0, 0.5}]
(* replaced y by y[x] and 0/5 by 0.5    *)


-
y[x_, theta_, v_] := x*Tan[theta] - ((9.8*x^2)/(2*v^2*(.5 + (.5*Cos[2 theta ]))));
values = {theta -> 30 Degree, v -> 2};
Plot[y[x, theta, v] /. values, {x, 0, 0.5}, Frame -> True]


For explanation on use of /. for replacement of values in expression see http://reference.wolfram.com/mathematica/ref/ReplaceAll.html

To make it easy to make changes in parameters, Manipulate can be used

Manipulate[
Module[{x},
Plot[y[x, theta, v], {x, 0, to}, Frame -> True, ImageSize -> 300,
],

Grid[{
{Control[{{theta, 30 Degree, "theta?"}, 0, 360, 1}], Dynamic[theta]},
{Control[{{v, 2, "v?"}, 0, 10, .1}], Dynamic[v]},
{Control[{{to, 1, "to?"}, .1, 10, .1}], Dynamic[to]}
}
],
Initialization :>
(
y[x_, theta_, v_] := x*Tan[theta]-((9.8*x^2)/(2*v^2*(.5 + (.5*Cos[2 theta ]))))
)
]


-
IMHO, introducing rules like this without explanation is not helpful for someone who is clearly very new to MMA and is struggling with assignments. I would suggest assigning variables like the OP, but correctly with =. – Pickett Jan 11 '14 at 23:58