Ballistic MotionGeorge Gillette & Don Van HyuckMATH 151 Honors 202/201Fall 2013Instructor: Philip Yasskin
Serious
The first hint was just wrong. The x equation has no (1/2)at^2. The 2 equations are not the same!In the second hint, v(x) and v(y) should be vx(t) and vy(t).In the ask proc, your formula for yt was wrong: missing the 1/2 in the t^2 term!
Not serious
I revised the layout a little.
Each column needs valign=none,, each row needs halign=none.The third and fourth hints needed to be simplified.
restart:with(Maplets[Tools]): with(Maplets[Elements]): with(plots):
StartEngine();
The following are lists of quotes to provide feedback and generate problems
They are then randomly selected by the rand commands
right := ["Bullseye!", "Great!", "That's absolutely right!", "You're unstoppable!", "Correct!", "You nailed that one!", "YES!", "Way to go!", "I knew you could do it!", "Perfecto!", "You're awesome!", "That's amazing!", "You're a math whiz!", "Whoop!", "Nice job!", "That's right!", "That's the way!", "I like the sound of that!", "Ding! That's correct!", "You're a genius!", "Right on the mark!", "Brick...house!", "Oh yeah!", "Wonderful!", "Excellent!", "You got it!", "Can I get a what what!", "Holla!", "Youre incredible!", "You got 'em coach!"]: rightrand := rand(1..nops(right)):wrong := ["Try again.", "Nope. I'm sorry.", "C'mon, you can do it.", "You can do better.", "You're close.", "Look closer.", "Put on your thinking cap.", "Better luck next time.", "Keep trying.", "Never give up.", "Try again. I have faith in you.", "Try harder."]:wrongrand := rand(1..nops(wrong)):final := ["You know your stuff! Move on to the next one!", "You're doing so awesome! Keep on keepin on!", "Wow! That's awesome! Don't stop now!", "You got all of them right! Way to go! Go on to the next problem!", "You're doing great! Keep on truckin!", "Oh yeah! Try the next function!"]:finalrand := rand(1..nops(final)):hint := ["Now try it yourself.", "There it is. Now figure it out.", "The hint is great, but try it yourself.", "That was practice. Try it again.", "Dont settle for the hint. Work it out."]:hintrand := rand(1..nops(hint)):thrownobjects := ["A misbehaving student", "A tiara", "The Hope Diamond", "A refrigerator", "A football", "A box", "A dirty diaper", "A battleaxe", "A watermelon", "A malfunctioning computer", "An adorable kitten"]:randthrownobjects := rand(1 .. nops(thrownobjects)):throwingmechanisms := ["is tossed by a child", "is jettisoned off of a boat", "is fired from a soviet missile launcher", "is slung by an ogre", "is thrown by Johnny Manziel", "is shot-put by a 400 pound man", "is thrown by an angry college student", "is catapulted out of a medieval castle", "is thrown out of a burning building", "is hurled by Dr. Yasskin", "is kicked upwards by a t-rex (he dropped it and can't pick it back up)"]:randthrowingmechanism := rand(1..nops(throwingmechanisms)):
Random numbers are generated in reasonable ranges for starting x and y values, velocity, and angle theta
genxy:=rand(0..10):
genvel:=5*rand(2..10):
gentheta:=15*rand(2..4):
The following ask command that is called upon each time a new function is generated. Ask creates local variables x0, y0, v0, and theta0 that will be utilized for the solutions to the problem. The ask procedure then calculates the correct answers to the user prompts for the x(t), y(t), vx(t), vy(t), time at the maximum height of the function, the maximum height of the function, time at the maximum distance of the function, and maximum distance of the function. It also clears the text boxes for all of the responses, setting them to a blank "" in order to allow the user to input new information.
ask:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
local throwingmechanism, thrownobject, x0, y0, v0, theta0;
throwingmechanism := throwingmechanisms[randthrowingmechanism()];
thrownobject := thrownobjects[randthrownobjects()];
x0:=genxy();
y0:=genxy();
v0:=genvel();
theta0:=gentheta();
Set(TFProb=sprintf("%s %s\134nfrom the point (x0, y0) = (%a,%a)\134nwith initial speed v0 = %a\134nat an angle of theta0 = %a above the horizontal.\134nAssume the acceleration of gravity is g = -9.8 m/sec^2.\134nAnswer each of the following questions to three significant figures. \134nEvaluate all trigonometric functions.", thrownobject, throwingmechanism, x0, y0, v0, theta0));
xt := x0 + v0*cos(theta0*Pi/180)*t;
yt := y0 + v0*sin(theta0*Pi/180)*t - 4.9*t^2;
vxt := diff(xt, t);
vyt := diff(yt, t);
theightmax := solve(vyt = 0);
heightmax := eval(yt, t = theightmax);
tdistancemax := fsolve(yt = 0, t = 0..1000);
distancemax := eval(xt, t = tdistancemax);
Set(answerxt=""):
Set(answeryt=""):
Set(responsexy="", responsexy(background)=white);
Set(answervxt=""):
Set(answervyt=""):
Set(responsevt="", responsevt(background)=white);
Set(answertheightmax=""):
Set(answerheightmax=""):
Set(responseheightmax="", responseheightmax(background)=white);
Set(answertdistancemax=""):
Set(answerdistancemax=""):
Set(responsedistancemax="", responsedistancemax(background)=white);
Set(reply="", reply(background)=white);
end proc:
These lines provide the user with "hint" feedback when the hint button is pressed, giving key information about the question.
hintxy:=proc()
Set(reply = "The position of an object moving in Earth's gravity is given by\134n x(t) = x0 + v0 cos(theta0) t y(t) = y0 + v0 sin(theta0) t - (1/2) g t^2.",
reply(background) = "Orange", reply(foreground) = black);
end proc:hintv:=proc()
Set(reply = "The components of the velocity, vx(t) and vy(t), are the derivatives of the position components, x(t) and y(t).",
reply(background) = "Orange", reply(foreground) = black);
end proc:hintheightmax:=proc()
Set(reply = "The object will reach its maximum height is when vy(t) is equal to zero. The maximum height is y(t) at that time.",
reply(background) = "Orange", reply(foreground) = black);
end proc:hintdistancemax:=proc()
Set(reply = "The object will reach its maximum distance is when y(t) = 0. The maximum distance is y(t) at that time.",
reply(background) = "Orange", reply(foreground) = black);
end proc:
This segment of code is the check mechanism for the Maplet. The check mechanism functions by creating a local variable with the prefix "user" to store the input from the user in the answer box. It proceeds to check the answer through a nested if statement: it rounds both the correct answer and the given answer to three significant figures, takes the difference between them, and simplifies the result. If that is now equal to zero, meaning that both the user input and the answer were identical, then it proceeds to check the other input from the user in the next if statement. If both were identical, this means that the answer was correct, and the check mechanism proceeds to change the color of the response box accordingly.
checkxy:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
local userxt, useryt;
userxt:=Get(answerxt::anything, corrections = true, update = true):
useryt:=Get(answeryt::anything, corrections = true, update = true):
if simplify(evalf(userxt, 3) - evalf(xt, 3)) = 0 then
if simplify(evalf(useryt, 3) - evalf(yt, 3)) = 0 then
Set(responsexy = "Correct",
responsexy(background)=green, responsexy(foreground) = black);
Set(reply = right[rightrand()],
reply(background) = green, reply(foreground) = black);
else
Set(responsexy = "Incorrect",
responsexy(background) = red, responsexy(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
else
Set(responsexy = "Incorrect",
responsexy(background) = red, responsexy(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
end proc:
This segment of code is the show mechanism for the Maplet. The show mechanism functions by setting the "answer" box equal to the correct answer set from the ask function, rounded to three significant figures. It then proceeds to change the color of the response box accordingly to yellow.
showxy:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
Set(answerxt = evalf(xt, 3));
Set(answeryt = evalf(yt, 3));
Set(responsexy="Shown",
responsexy(background)=yellow, responsexy(foreground)=black);
Set(reply=hint[hintrand()],
reply(background)=yellow, reply(foreground)=black);
end proc:
The check and show mechanisms are then repeated for the remaining variables, named appropriately to their function.
checkv:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
local uservxt, uservyt;
uservxt:=Get(answervxt::anything, corrections = true, update = true):
uservyt:=Get(answervyt::anything, corrections = true, update = true):
if simplify(evalf(uservxt, 3) - evalf(vxt, 3)) = 0 then
if simplify(evalf(uservyt, 3) - evalf(vyt, 3)) = 0 then
Set(responsevt = "Correct",
responsevt(background)=green, responsevt(foreground) = black);
Set(reply = right[rightrand()],
reply(background) = green, reply(foreground) = black);
else
Set(responsevt = "Incorrect",
responsevt(background) = red, responsevt(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
else
Set(responsevt = "Incorrect",
responsevt(background) = red, responsevt(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
end proc:showv:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
Set(answervxt = evalf(vxt, 3));
Set(answervyt = evalf(vyt, 3));
Set(responsevt="Shown",
responsevt(background)=yellow, responsevt(foreground)=black);
Set(reply=hint[hintrand()],
reply(background)=yellow, reply(foreground)=black);
end proc:checkheightmax:=proc()
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
local usertheightmax, userheightmax;
usertheightmax:=Get(answertheightmax::anything, corrections = true, update = true):
userheightmax:=Get(answerheightmax::anything, corrections = true, update = true):
if simplify(evalf(usertheightmax, 3) - evalf(theightmax, 3)) = 0 then
if simplify(evalf(userheightmax, 3) - evalf(heightmax, 3)) = 0 then
Set(responseheightmax = "Correct",
responseheightmax(background)=green, responseheightmax(foreground) = black);
Set(reply = right[rightrand()],
reply(background) = green, reply(foreground) = black);
else
Set(responseheightmax = "Incorrect",
responseheightmax(background) = red, responseheightmax(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
else
Set(responseheightmax = "Incorrect",
responseheightmax(background) = red, responseheightmax(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
end proc:QyQ+SS5zaG93aGVpZ2h0bWF4RzYiZipGJUYlRiVGJUMmLUkkU2V0R0YlNiMvSTFhbnN3ZXJ0aGVpZ2h0bWF4R0YlLUkmZXZhbGZHJSpwcm90ZWN0ZWRHNiRJK3RoZWlnaHRtYXhHRiUiIiQtRik2Iy9JMGFuc3dlcmhlaWdodG1heEdGJS1GLjYkSSpoZWlnaHRtYXhHRiVGMi1GKTYkL0kycmVzcG9uc2VoZWlnaHRtYXhHRiVRJlNob3duRiUvLUY9NiNJK2JhY2tncm91bmRHRiVJJ3llbGxvd0dGJS1GKTYlL0kmcmVwbHlHRiUmSSVoaW50R0YlNiMtSSloaW50cmFuZEdGJUYlLy1GR0ZBRkMvLUZHNiNJK2ZvcmVncm91bmRHRiVJJmJsYWNrR0YlRiU2KkkjeHRHRiVJI3l0R0YlSSR2eHRHRiVJJHZ5dEdGJUY5RjFJLGRpc3RhbmNlbWF4R0YlSS10ZGlzdGFuY2VtYXhHRiVGJSEiIg==checkdistancemax:=proc()
local usertdistancemax, userdistancemax;
global xt, yt, vxt, vyt, heightmax, theightmax, distancemax, tdistancemax;
usertdistancemax:=Get(answertdistancemax::anything, corrections = true, update = true):
userdistancemax:=Get(answerdistancemax::anything, corrections = true, update = true):
if simplify(evalf(usertdistancemax, 3) - evalf(tdistancemax,3)) = 0 then
if simplify(evalf(userdistancemax, 3) - evalf(distancemax, 3)) = 0 then
Set(responsedistancemax = "Correct",
responsedistancemax(background)=green, responsedistancemax(foreground) = black);
Set(reply = right[rightrand()],
reply(background) = green, reply(foreground) = black);
else
Set(responsedistancemax = "Incorrect",
responsedistancemax(background) = red, responsedistancemax(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
else
Set(responsedistancemax = "Incorrect",
responsedistancemax(background) = red, responsedistancemax(foreground) = white);
Set(reply = wrong[wrongrand()],
reply(background) = red, reply(foreground) = white);
end if;
end proc:QyQ+STBzaG93ZGlzdGFuY2VtYXhHNiJmKkYlRiVGJUYlQyYtSSRTZXRHRiU2Iy9JM2Fuc3dlcnRkaXN0YW5jZW1heEdGJS1JJmV2YWxmRyUqcHJvdGVjdGVkRzYkSS10ZGlzdGFuY2VtYXhHRiUiIiQtRik2Iy9JMmFuc3dlcmRpc3RhbmNlbWF4R0YlLUYuNiRJLGRpc3RhbmNlbWF4R0YlRjItRik2JC9JNHJlc3BvbnNlZGlzdGFuY2VtYXhHRiVRJlNob3duRiUvLUY9NiNJK2JhY2tncm91bmRHRiVJJ3llbGxvd0dGJS1GKTYlL0kmcmVwbHlHRiUmSSVoaW50R0YlNiMtSSloaW50cmFuZEdGJUYlLy1GR0ZBRkMvLUZHNiNJK2ZvcmVncm91bmRHRiVJJmJsYWNrR0YlRiU2KkkjeHRHRiVJI3l0R0YlSSR2eHRHRiVJJHZ5dEdGJUkqaGVpZ2h0bWF4R0YlSSt0aGVpZ2h0bWF4R0YlRjlGMUYlISIi
The following code executes the Ballistic Maplet. It begins by randomly generating the problem upon pressing the button "New Function." It then proceeds to create text fields for the user input for the different questions asked about the ballistic motion of a random object. This creates multiple buttons, particularly the check, show, and hint buttons for the different questions. Each button refers to the responses generated by the above code and displays them to the user interface. There is a text field at the bottom of the window designed to provide feedback to the user according to the randomly generated responses at the top of this code and the hint button responses.
Ballistics:=Maplet(onstartup = RunWindow(MAIN), Font[helv10]("helvetica",10),
Window[MAIN](title="Ballistic Motion",
[ valign=none,
[ halign=none,
Button("New Problem", Evaluate(function = "ask"), background=magenta),
HorizontalGlue(),
[ valign=none, inset=0, spacing=0, border=true,
caption="Problem:",
TextBox[TFProb]( width=70, height=8)
],
HorizontalGlue(),
Button("Quit", Shutdown(), background=pink)
],
[ halign=none, border=true,
caption="Enter the position as a function of time:",
"x(t) =",
TextField[answerxt](width=25, background=turquoise),
HorizontalGlue(),
"y(t) =",
TextField[answeryt](width=25, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function = "hintxy"), background=Orange),
Button("Check", Evaluate(function = "checkxy"), background=green),
TextField[responsexy](width=6, editable=false, background=white),
Button("Show", Evaluate(function = "showxy"), background=yellow)
],
[ halign=none, border=true,
caption="Enter the velocity as a function of time:",
"vx(t) =",
TextField[answervxt](width=25, background=turquoise),
HorizontalGlue(),
"vy(t) =",
TextField[answervyt](width=25, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function = "hintv"), background=Orange),
Button("Check", Evaluate(function = "checkv"), background=green),
TextField[responsevt](width=6, editable=false, background=white),
Button("Show", Evaluate(function = "showv"), background=yellow)
],
[ halign=none, border=true,
caption="When will it reach a maximum height? What is the maximum height?:",
"t =",
TextField[answertheightmax](width=25, background=turquoise),
HorizontalGlue(),
"Maximum Height =",
TextField[answerheightmax](width=25, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function = "hintheightmax"), background=Orange),
Button("Check", Evaluate(function= "checkheightmax"), background=green),
TextField[responseheightmax](width=6, editable=false, background=white),
Button("Show", Evaluate(function="showheightmax"), background=yellow)
],
[ halign=none, border=true,
caption="When will it hit the ground? Where will it hit?:",
"t =",
TextField[answertdistancemax](width=25, background=turquoise),
HorizontalGlue(),
" Final X Position =",
TextField[answerdistancemax](width=25, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function = "hintdistancemax"), background=Orange),
Button("Check", Evaluate(function= "checkdistancemax"), background=green),
TextField[responsedistancemax](width=6, editable=false, background=white),
Button("Show", Evaluate(function= "showdistancemax"), background=yellow)
],
TextBox[reply](width=50, height=2),
[ halign=none, inset=0, spacing=0,
"Instructor: Philip Yasskin",
HorizontalGlue(),
"Programmers: George Gillette & Don Van Hyuck",
HorizontalGlue(),
"Copyright: Yasskin 2013"
]
]
)
):Maplets:-Display( Ballistics );