CS 122 Computational Lab II Winter 2008

advertisement
CS 123
Computational Lab IIl
Spring 2008
Department of Computer Science
Drexel University
Copyright by the authors. Permission is given for students and staff
of CS 123 Spring 2008 to reproduce these notes for their own use.
Calendar
Lab 1
Activity
Due Date
Week 2
Week 3
Quiz 1
Lab 2
Week 3
Week 4
Quiz 2
Week 5
Week 5
Lab 3
Week 6
Week 7 (16th May5P.M)
Quiz 3
Start : 10th May
Week 7 (16th May5P.M)
Lab 4
Week 8
Week 9
Quiz 4
Week 9
Lab exam (in class)
Week 10
Important Note about Today’s Lab
1)You are required to work in a group
2)You don't get credit for the lab until you
show a TA or instructor your results from the
end of the lab. You can do this at the end of
the lab period, or by dropping into the Cyber
Learning Center next week. If you do not
get "checked in" by a staff member, then
you will receive no credit for this lab even if
you attended a Lab session
So, What is today’s Lab about?


Animating with maple : use “animate” command
to create maple simulations
We will simulate cannon simulation and the
“Blammo” game
One dimensional motion
•Assuming we have 1 dimensional motion:
Velocity:
v(t) = -gt + v(0)
Displacement:
y(t) = int(-gt + v(0)) dt
= -1/2gt^2+v(0) t + D
Maple Simulation of one
dimensional motion:

Let’s look at maple code:
> a := -32; # feet/second^2;
> v := int(a, t) + v0;
> y := int(v, t);
> tpeak := solve(v=0, t); # time to reach peak
> ymax := eval(y, t=tpeak); # height of peak
> soln := solve(y=0, t); # times when on the ground
> tmax := max(soln); # select later time
> tmax := simplify(tmax, assume=positive); # assume v0 > 0 to simplify
> tmax = 2*tpeak; # confirm

Animate : animate(pointplot, [[0,y]], t=0..tmax, symbolsize=20);
2 New Maple commands:
1) Animate :
-what does it do?
> create a 2-D or 3-D animation on one parameter
-How to use it?
> animate(plotcommand, plotargs, t=a..b, options)
Example:: animate(pointplot, [[0,y]], t=0..tmax, symbolsize=20);
2) Evalb :
- what does it do ? Evaluates a Boolean Expression
-how to use it ? Evalb(x)
example : >evalb(evalf(sqrt(5))>2);
True
Using Defined Procedures to make a
game!
Let’s take a closer look at defined procedures and how we can use them:
1)VerticalPosition : checks if the disk hits the bell / derive the equations
1) VerticalPosition:=proc(t,v0,h)
2)MaxTime determines the time when the disk returns to the ground
1) MaxTime := proc(v0, h)
3)PlayGame: Given the initial velocity v0 of the disk and the height h of the
bell, procedure PlayGame uses the animate command to simulate the hitthe-bell game.
1) PlayGame:= proc(v0, h)
Two Dimensional Motion:
h
x(t) = V0x * t
y(t) = y0 + V0y*t -1/2g*t^2
Same approach as 1 dimCode up procedures on yourself!
Procedures you need to write:
1) HitsNet(initial velocity, angle (measured in radians) distance to net, size of net)
which returns true if Blammo lands on any part of the net and returns false otherwise.
2) XYPosition(time, initial velocity, angle)
which returns a list with two elements, namely expressions for the x and y
coordinates of the position of Blammo at time t : USE PREVIOUS EQ!
3) MaxTime(initial velocity, angle)
which returns the time when Blammo hits the ground
Y = 0 , X = X final = R
4) ShootCannon(initial velocity, angle, distance to net, size of net)
which creates an animation of Blammo being shot from the cannon towards the net.
USE PREVIOUSE FUNCTIONS + ANIMATE
Parametric Curves in Maple
We can plot curves in Maple using PLOT command:
plot([x(t), y(t), t=range of t], h, v, options)
[x,y,range] - parametric specifications
h
- horizontal range
v
- vertical range
Example:
>plot([(t^2-1)/(t^2+1), 2*t/(t^2+1), t=-infinity..infinity]);
What if we have wind resistance ?
Let’s consider the case of having resistance:
Basic idea :
Acceleration is
changed : F=M.A
How we use it?
-Vx-wind , x-wind
-Vy-wind , y-wind
Use Procedures/function to simulate Blammo
with/out resistance!
Lab structure




This lab is divided into the following
sections:
Required Reading: Introduction &
Overview, Tutorials 1-5, Wrap-Up
Required Problems: Problems 1-5
Optional Problems: Problems 6,7
Work in groups as always !!
Do not forget to CHECK IN !
What to turn in?!


Lab 3 Due May 16th,5 P.M
Quiz 3  Due May 16th ,5 P.M
-Submit your lab via Bb Vista
-We have office hours in UC145 next
week, if you had any problem in Quiz 2
feel free to stop by and ask questions!
 Good Luck!
Download