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.`

(which uses the secant method when the derivative of the function is not provided):**newton**

```
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
```

- Error in python code in Choregraphe
- Pandas: new column, sampled from list, based on column value
- How to correctly install rpy2 in python?
- How do I change the dataset when I Fine-Tuning the Whisper model?
- Customizing legend in Seaborn histplot subplots
- python issues with KeyError: skip over errors when data is not in the json?
- Print string to text file
- Explanation of reportAttributeAccessIssue of pylance
- Why is a test (100/100) leading to an unexpected output?
- Arrays Merging Instead of Appending in Python
- Why did I got an error ModuleNotFoundError: No module named 'distutils'?
- Python / Boto3: Float types are not supported. Use Decimal types instead
- Why is this regex not capturing the last input?
- How to fully disassemble Python source
- Following Links in HTML using BeautifulSoup
- Floating-point efficiency of Python library function implementations
- Convert set to a hashable type
- Why is my python code so slow (leetcode)?
- Getting individual colors from a color map in matplotlib
- How do self-assessing sites like Hackerrank and Leetcode check whether an answer is correct?
- Combine list of dictionaries in python
- Numpy, from a list of points, extract ones that have the same range of coordinates without for loop
- PostgreSQL - how to run VACUUM from code outside transaction block?
- Why is heap slower than sort for K Closest Points to Origin?
- How to get specific unique combinations of a dataframe using only dataframe operations?
- Make this data cleaning loop more Python
- How to set the working directory for debugging a Python program in VS Code?
- How to plot multiple slices of a 3D brain image with nilearn and matplotlib subplots
- Using nibabel to save nifti in "SPM" style
- I want to apply an algorithm to different images from a folder and save the new ones in another folder