Question: PYTHON PROGRAMING HELP Flight Trajectory Describe,formulaically,howyouwouldsolvefortheinstantaneousvelocityv(both magnitude and direction) at time t of a ball released with initial velocity v0. Assume that t0 = 0
PYTHON PROGRAMING HELP
Flight Trajectory
Describe,formulaically,howyouwouldsolvefortheinstantaneousvelocityv(both magnitude and direction) at time t of a ball released with initial velocity v0. Assume that t0 = 0 and the only force applied on the ball is due to Earths surface gravity. Implementthisalgorithmwithintrajectory()inlab1.py.Thefunctioninputsandoutputs have been defined in the function descriptor.
List Search
Describe,indetail,howyouwoulddeterminewhetheraspecifiednumberxexists within a given list. Assume the list is sorted in ascending order and you may query only one index at a time. Solve this as efficiently as possible. Implementthisalgorithmwithinlist_search()inlab1.py.Thefunctioninputsandoutputs have been defined in the function descriptor. Analyzethespaceandtimecomplexityofyourimplementationinrespecttolistsizen. Consider only conditional checks for time complexity. Consider only additional space required beyond initial list storage for space complexity. Give your answer in big-O notation and show all appropriate work.
Curve Balls
3.
You have been provided function curve_balls() in lab1.py. Note, this function uses helper functions curve_ball() and split_ball().
Analyzethetimecomplexityofthisfunctioninrespecttoinputstandn.Assumeeach explicit conditional check counts as an operation. Give your answer in big-O notation and show all appropriate work.
Analyzethespacecomplexityofthisfunctioninrespecttoinputstandn.Only consider the creation of Balls towards the total. Give your answer in big-O notation and show all appropriate work.
Observethetwohelperfunctionscurve_ball()andsplit_ball().Writeanappropriatefull function descriptor (including parameters and returns as needed) for each helper function.
CODE TEMPLATE BELOW
"""
This is your template for lab1. Implement all questions in the appropriate
function. You are encouraged to implement helper functions as needed with
a short (one-line) description of their purpose.
"""
import random
ACCEL_G = 9.8 # m/s^2
def trajectory(p0, v0, t):
"""
Calculates instaneous free-fall trajectory given initial parameters.
Object may start with any real position and velocity. Assume
acceleration
is ACCEL_G as specified above.
Parameters
----------
p0 : [float, float]
the position of the object at t0, given as [pos_x, pos_y]
v0 : [float, float]
the velocity of the object at t0, given as [vel_x, vel_y]
t : float
time passed since t0
Returns
-------
list(float)
instantaneous trajectory of object given as [pos_x, pos_y, vel_x,
vel_y]
"""
# replace the line below with your implementation
pass
def list_search(n, my_list=None):
"""
Search for the specified number in a given list.
Assume the input list is sorted in ascending order, but not
necessarily
consecutive. Integers may be repeated. Shoot for an expected runtime
of
log(n) for full credit.
Parameters
----------
n : int
the specific element to search for
my_list : list(int)
list of elements to search through
Returns
-------
int
the element's index within the list or -1 if the element is not
present
"""
# Generate a random list if no list is specified
if my_list is None:
my_list = []
list_size = 1000
int_range = 10000
for _ in range(list_size):
elem = random.randint(-int_range/2, int_range/2)
my_list.append(elem)
my_list.sort()
# replace the line below with your implementation
pass
class Ball:
def __init__(self, mass=10):
self.x = 0
self.y = 0
self.mass = mass
def curve_balls(t, n):
"""
Propagate the random movement and splitting of balls over time.
Assume the input list is sorted in ascending order, but not
necessarily
consecutive. Integers may be repeated. Shoot for an expected runtime
of
log(n) for full credit.
Parameters
----------
t : int
the number of time steps to propagate the algorithm
n : int
number of balls to initially start with
"""
# initialize list of balls
balls = []
for i in range(n):
balls.append(Ball())
# propagate balls through each timestep
for _ in range(t):
balls_generated = []
for b in balls:
curve_ball(b)
ball_new = split_ball(b)
balls_generated.append(ball_new)
balls += balls_generated # append all newly generated balls to
the list of balls
def curve_ball(ball):
"""
Write your function descriptor here.
Parameters
----------
"""
ball.x += random.uniform(-1,1)
ball.y += random.uniform(-1,1)
if ball.x > 10:
ball.x = 10
elif ball.x < -10:
ball.x = -10
if ball.y > 10:
ball.y = 10
elif ball.y < -10:
ball.y = -10
def split_ball(ball_og):
"""
Write your function descriptor here.
Parameters
----------
Returns
-------
"""
ball_og.mass /= 2
ball_new = Ball(mass=ball_og.mass)
ball_new.x = ball_og.x
ball_new.y = ball_og.y
return ball_new
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
