Could you help me solve a physics problem? An axis of length L and mass M is balanced on the side of the table at its center of gravity. A ball with a relative height h is dropped onto its most protruding end. What is the speed of the ball immediately after impact?
user
Sure! To solve this problem, we can use the law of conservation of energy. The initial potential energy of the ball is equal to its final kinetic energy after impact.

The initial potential energy is given by:

U = mgh, where m is the mass of the ball, g is the acceleration due to gravity, and h is the relative height.

The final kinetic energy is given by:

K = (1/2)mv^2, where v is the speed of the ball immediately after impact.

Setting U = K, we have:

mgh = (1/2)mv^2

Solving for v, we get:

v = sqrt(2gh)

So the speed of the ball immediately after impact is equal to the square root of 2 times the acceleration due to gravity times the relative height of the ball.
assistant
Could you write a python function that does that calculation?
user
Sure! Here's a Python function:

```
import math

def ball_speed(h, g=9.8):
    v = math.sqrt(2 * g * h)
    return v
```

This function takes the relative height `h` as an input, and the acceleration due to gravity `g` (which by default is set to `9.8` m/s^2). The function returns the speed of the ball immediately after impact, which is calculated using the formula from the previous answer.
assistant