La seconda legge di Newton¶

da PowerShell -- jupyter nbconvert --to html notebook.ipynb

In un sistema di particelle la velocità del centro di massa è la media pesata delle singole velocità¶

$$\large v_{cm}=\frac{p_{tot}}{M}=\frac{\sum m\, v_i}{\sum m_i}$$

L'accelerazione del centro di massa è la media pesata delle singole accelerazioni¶

$$\large a_{cm}=\frac{F_{tot}}{M}=\frac{\sum m\, a_i}{\sum m_i}$$
In [8]:
import numpy as np 

def calculate_force(mass, acceleration):
    """
    Calculate the net force applied to an object.
        :param mass: Mass of the object.
        :param acceleration: Acceleration vector of the object.
    :return: Force vector.
    """
    return mass * np.array(acceleration)

def calculate_acceleration(force, mass):
    """
    Calculate the acceleration of an object.
        :param force: Force vector applied to the object.
        :param mass: Mass of the object.
    :return: Acceleration vector.
    """
    return np.array(force) / mass

def differential_form(mass, velocity, time):
    """
    Calculate differential representation of Newton's Second Law.
        :param mass: Mass of the object.
        :param velocity: Velocity vector of the object.
        :param time: Time interval.
    :return: Force vector using momentum change.
    """
    momentum_initial = mass * np.array(velocity[0])
    momentum_final = mass * np.array(velocity[1])
    delta_momentum = momentum_final - momentum_initial
    return delta_momentum / time 

def system_of_particles(forces, masses, velocities):
    """
    Generalize the second law for a system of particles.
        :param forces: List of external force vectors on particles.
        :param masses: List of masses for each particle.
        :param velocities: Initial and final velocity for each particle.
    :retum: Center of mass acceleration vector.
    """
    total_force = np.sum(forces, axis=0)
    total_mass = np.sum(masses)
    velocity_changes = [differential_form(masses[i], velocities [i],1) for i in range(len(masses))]
    avg_acceleration = np.sum(velocity_changes, axis=0) / len(masses)
    return total_force / total_mass, avg_acceleration

# Example usage
np.set_printoptions(formatter={'float_kind': lambda x: f"{x:.3f}"})
mass =10 # kg
acceleration = [2, 0, -1] # m/s^2
force = calculate_force(mass, acceleration)
print("Force:", force)

force_vector = [20, 0, -10] # Newtons
calculated_acceleration = calculate_acceleration(force_vector, mass)
print("Calculated Acceleration:", calculated_acceleration)

velocities = [[0, 0, 0], [2, 0, -1]] # Initial and final velocity
force_differential = differential_form(mass, velocities, 2)
print("Differential Force:", force_differential)

# System of particles example
forces = [[10, 0, 0], [15, 5, 0], [0, 10, 5]]
masses = [5, 10, 7]
velocities = [[[0, 0, 0], [1, 0, 0]], [[0, 0, 0], [1.5, 0.5, 0]], [[0, 0, 0] , [0, 1, 0.5]]]
center_mass_acceleration, avg_acceleration = system_of_particles(forces, masses, velocities)
print("Center of Mass Acceleration:", center_mass_acceleration)
print("Average Acceleration:", avg_acceleration)
Force: [ 20   0 -10]
Calculated Acceleration: [2.000 0.000 -1.000]
Differential Force: [10.000 0.000 -5.000]
Center of Mass Acceleration: [1.136 0.682 0.227]
Average Acceleration: [6.667 4.000 1.167]
In [ ]: