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.

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!

share|improve this question
2  
== 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 at 23:53
3  
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 at 23:57
add comment

2 Answers

θ = π/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    *)

Mathematica graphics

share|improve this answer
add comment
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]

Mathematica graphics

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, 
        ImagePadding -> 30]
  ],

 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 ]))))
   )
 ]

enter image description here

share|improve this answer
3  
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 at 23:58
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.