Average and Instantaneous Velocity
Victor Leon & Aidan Riley
Math 151 Honors Section 201
Fall 2013
Instructor: Philip Yasskin
Serious
Your ans_v2 and ans_v3 are wrong! Divide by h, not 2. Fixed
Not Serious
I put more information in your header in the worksheet.
I reformatted the layout.
In make_eq, you need to blank out the Reply box.
You need halign=none on all the rows. Columns get valign.
I revised your hint.
Don't use single letter variable names.
I expanded ans_v2 and ans_v3. Then in the check I first check for the simplified answer followed by a check for the unsimplified answer and give a warning.
restart:
with(Maplets[Tools]): with(Maplets[Elements]):
StartEngine();
randomize():
randcoeff := rand(1..7):
randpower := rand(1..3):
make_eq := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local a1, b1, c1, d1, xfunc, vfunc:
a1 := randcoeff():
b1 := randpower():
c1 := randcoeff():
d1 := randpower():
xfunc := t -> a1*t^b1+t^(d1-1)+c1:
vfunc := t -> eval(diff(xfunc(x),x),x=t):
ans_v1 := (xfunc(5) - xfunc(3)) / 2:
ans_v2 := expand((xfunc(3+h)-xfunc(3)) / h):
ans_v3 := expand((xfunc(a+h)-xfunc(a)) / h):
ans_v4 := vfunc(3):
ans_v5 := vfunc(a):
Set(TFx1=xfunc(t)):
Set(TFv1=""):
Set(MRv1="", MRv1(background) = white):
Set(TFv2=""):
Set(MRv2="", MRv2(background) = white):
Set(TFv3=""):
Set(MRv3="", MRv3(background) = white):
Set(TFv4=""):
Set(MRv4="", MRv4(background) = white):
Set(TFv5=""):
Set(MRv5="", MRv5(background) = white):
Set(Reply="", Reply(background) = white):
end proc:
Hint := proc()
Set(Reply=" Average Velocity = (change in position) / (change in time).\134n Instantaneous Velocity is the limit of the Average Velocity as the change in time (h) goes to zero.",
Reply(background) = Orange);
end proc:
Ckv1 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local ans_user:
ans_user := Get(TFv1::realcons, corrections = true, update = true):
if simplify(ans_user - ans_v1) = 0 then
Set(MRv1="Correct", MRv1(background) = green, MRv1(foreground) = black):
else
Set(MRv1="Incorrect", MRv1(background) = red, MRv1(foreground) = black):
end if:
end proc:
Shv1 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
Set(MRv1="Shown", MRv1(background) = Orange, MRv1(foreground) = black):
Set(TFv1=ans_v1):
end proc:
Ckv2 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local ans_user:
ans_user := Get(TFv2::algebraic, corrections = true, update = true):
if ans_user = ans_v2 then
Set(MRv2="Correct", MRv2(background) = green, MRv2(foreground) = black):
elif simplify(ans_user - ans_v2) = 0 then
Set(MRv2="Almost", MRv2(background) = yellow, MRv2(foreground) = black):
Set(Reply="You should simplify your answer.", Reply(background) = yellow, Reply(foreground) = black):
else
Set(MRv2="Incorrect", MRv2(background) = red, MRv2(foreground) = black):
end if:
end proc:
Shv2 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
Set(MRv2="Shown", MRv2(background) = Orange, MRv2(foreground) = black):
Set(TFv2=ans_v2):
end proc:
Ckv3 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local ans_user:
ans_user := Get(TFv3::algebraic, corrections = true, update = true):
if ans_user = ans_v3 then
Set(MRv3="Correct", MRv3(background) = green, MRv3(foreground) = black):
elif simplify(ans_user - ans_v3) = 0 then
Set(MRv3="Almost", MRv3(background) = yellow, MRv3(foreground) = black):
Set(Reply="You should simplify your answer.", Reply(background) = yellow, Reply(foreground) = black):
else
Set(MRv3="Incorrect", MRv3(background) = red, MRv3(foreground) = black):
end if:
end proc:
Shv3 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
Set(MRv3="Shown", MRv3(background) = Orange, MRv3(foreground) = black):
Set(TFv3=ans_v3):
end proc:
Ckv4 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local ans_user:
ans_user := Get(TFv4::realcons, corrections = true, update = true):
if simplify(ans_user - ans_v4) = 0 then
Set(MRv4="Correct", MRv4(background) = green, MRv4(foreground) = black):
else
Set(MRv4="Incorrect", MRv4(background) = red, MRv4(foreground) = black):
end if:
end proc:
Shv4 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
Set(MRv4="Shown", MRv4(background) = Orange, MRv4(foreground) = black):
Set(TFv4=ans_v4):
end proc:
Ckv5 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
local ans_user:
ans_user := Get(TFv5::algebraic, corrections = true, update = true):
if simplify(ans_user - ans_v5) = 0 then
Set(MRv5="Correct", MRv5(background) = green, MRv5(foreground) = black):
else
Set(MRv5="Incorrect", MRv5(background) = red, MRv5(foreground) = black):
end if:
end proc:
Shv5 := proc()
global ans_v1, ans_v2, ans_v3, ans_v4, ans_v5:
Set(MRv5="Shown", MRv5(background) = Orange, MRv5(foreground) = black):
Set(TFv5=ans_v5):
end proc:
Velocity:=Maplet(onstartup = RunWindow(MAIN),
Window[MAIN](title="Average and Instantaneous Velocity",
[ valign=none, inset=0,spacing=0,
[ halign=none,
Button("New Position", onclick=new_pos, background = magenta),
BoxRow( halign=none, inset=0, spacing=0, border = true,
caption="A car is travelling along a straight road and its position at time t is",
HorizontalGlue(),
"x(t) = ", TextField[TFx1](width = 20, editable = false, background = white),
HorizontalGlue()
),
Button("Hint", onclick=Hint, background=Orange),
Button("Quit", Shutdown(), background = pink)
],
BoxColumn( valign = none, inset=0,spacing=0, border = true,
caption = "Part 1: Find the average velocity",
[ halign=none,
"between t = 3 and t = 5: v_avg =",
TextField[TFv1](width = 20, background = turquoise),
HorizontalGlue(),
Button("Check", onclick = Ckv1, background=green),
TextField[MRv1](width=6,background = white),
Button("Show", onclick = Shv1, background = Orange)
],
[ halign=none,
"between t = 3 and t = 3 + h: v_avg =",
TextField[TFv2](width = 20, background = turquoise),
HorizontalGlue(),
Button("Check", onclick = Ckv2, background=green),
TextField[MRv2](width=6,background = white),
Button("Show", onclick = Shv2, background = Orange)
],
[ halign=none,
"between t = a and t = a + h: v_avg =",
TextField[TFv3](width = 20, background = turquoise),
HorizontalGlue(),
Button("Check", onclick = Ckv3, background = green),
TextField[MRv3](width=6,background = white),
Button("Show", onclick = Shv3, background = Orange)
]
),
BoxColumn( valign = none, inset=0,spacing=0, border = true,
caption = "Part 2: Find the instantaneous velocity",
[ halign=none,
"at t = 3: v =",
TextField[TFv4](width = 10, background = turquoise),
HorizontalGlue(),
Button("Check", onclick = Ckv4, background = green),
TextField[MRv4](width=6,background = white),
Button("Show", onclick = Shv4, background = Orange)
],
[ halign=none,
"at t = a: v =",
TextField[TFv5](width = 10, background = turquoise),
HorizontalGlue(),
Button("Check", onclick = Ckv5, background = green),
TextField[MRv5](width=6,background = white),
Button("Show", onclick = Shv5, background = Orange)
]
),
TextBox[Reply](width = 50, height = 3, background = white, editable = false),
[ halign=none, inset=0, spacing=0,
"Instructor: Philip Yasskin",
HorizontalGlue(),
"Programmers: Victor Leon & Aidan Riley",
HorizontalGlue(),
"Copyright: Yasskin 2013"
]
]
),
Action[test](),
Action[new_pos](Evaluate(function = "make_eq")),
Action[Ckv1](Evaluate(function = "Ckv1")),
Action[Shv1](Evaluate(function = "Shv1")),
Action[Ckv2](Evaluate(function = "Ckv2")),
Action[Shv2](Evaluate(function = "Shv2")),
Action[Ckv3](Evaluate(function = "Ckv3")),
Action[Shv3](Evaluate(function = "Shv3")),
Action[Ckv4](Evaluate(function = "Ckv4")),
Action[Shv4](Evaluate(function = "Shv4")),
Action[Ckv5](Evaluate(function = "Ckv5")),
Action[Shv5](Evaluate(function = "Shv5")),
Action[Hint](Evaluate(function = "Hint"))
):
Maplets[Display]( Velocity );