pythonphysics

create python code to figure out start velocity


Have a task and need to figure out the start velocity of an iron ball shot vertically upwards. We know this information.


Solution

  • The values from your image are as follows:

    • mass sphere: 263.8602726 kg
    • drag coefficient: 0.47
    • air density: 1.225 kg/m³
    • max height: 80 m
    • acceleration due to gravity (G): 9.805 m/s²

    Assuming you can neglect air resistance, you could use the kinematic equation:

    v^2 + u^2 = 2as
    

    where:

    • v is the final velocity (0 m/s at the maximum height).
    • u is the start velocity.
    • a is the acceleration (in this case, -9.805 m/s² due to gravity).
    • s is the displacement (80 m).

    We can rearrange the equation to solve for the start velocity u:

    u = sqrt(v^2 -2as)
    

    Implementing this in Python is relatively straightforward:

    def calculate_start_velocity(displacement: float,
                                 acceleration: float) -> float:
      """Calculate the start velocity for an object given its displacement and acceleration.
    
      Args:
          displacement: The displacement of the object (maximum height reached).
          acceleration: The acceleration (should be negative for gravity).
    
      Returns:
          float: The calculated start velocity.
      """
      final_velocity_squared = 0  # Since final velocity at max height is 0.
      start_velocity_squared = final_velocity_squared - 2 * acceleration * displacement
      start_velocity = start_velocity_squared**0.5
      return start_velocity
    
    
    def main() -> None:
      """Main function to calculate and print the start velocity."""
      max_height = 80.0  # Displacement.
      gravity = -9.805  # Acceleration due to gravity.
      start_velocity = calculate_start_velocity(max_height, gravity)
      print(f'Initial velocity of the sphere: {start_velocity:.2f} m/s')
    
    
    if __name__ == '__main__':
      main()
    
    

    Output:

    Initial velocity of the sphere: 39.61 m/s
    

    Assuming that air resistance is supposed to be taken into account you can use scipy.optimze.newton (which uses the secant method when the derivative of the function is not provided):

    import numpy as np
    from scipy.optimize import newton
    
    
    def find_initial_velocity(v0, mass, drag_coefficient, air_density, diameter, g,
                              max_height):
      """
      Compute the difference between the calculated max height and actual 
      max height for a given initial velocity considering air resistance.
      """
      # Time step for numerical simulation
      dt = 0.01  # in seconds
      velocity = v0
      height = 0
      while velocity > 0:
        # Drag force
        area = np.pi * (diameter / 2)**2
        drag_force = 0.5 * drag_coefficient * air_density * area * velocity**2
        # Net acceleration (both gravity and drag slow down the sphere)
        acceleration = g + drag_force / mass
        # Update velocity and height
        velocity -= acceleration * dt
        height += velocity * dt
      return height - max_height
    
    
    def main():
      """Calculate the initial velocity of a sphere shot upwards."""
      # Given constants
      mass = 263.8602726  # in kg
      density_of_iron = 7874  # in kg/m^3
      drag_coefficient = 0.47
      air_density = 1.225  # in kg/m^3
      max_height = 80  # in m
      g = 9.805  # in m/s^2
      # Calculate diameter of the sphere
      volume = mass / density_of_iron
      radius = (3 * volume / (4 * np.pi))**(1 / 3)
      diameter = 2 * radius
      # Initial guess for the initial velocity
      initial_guess = np.sqrt(2 * g * max_height)
      # Find the initial velocity using the Secant method
      initial_velocity = newton(find_initial_velocity,
                                initial_guess,
                                args=(mass, drag_coefficient, air_density,
                                      diameter, g, max_height))
    
      print(f'Initial velocity of the sphere: {initial_velocity:.2f} m/s')
    
    
    if __name__ == '__main__':
      main()
    

    Output:

    Initial velocity of the sphere: 39.88 m/s