Here's a Python code using NumPy, SciPy, and Matplotlib libraries to calculate and plot the trajectory of a body (assuming it's a projectile) thrown with an initial speed V_0 and angle alpha. The air resistance (drag force) is taken into account by using the drag coefficient Cd and object's density rho.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Constants
G = 9.81 # Gravity acceleration (m/s²)
# Projectile's initial conditions
V_0 = 20 # Initial velocity (m/s)
alpha = np.deg2rad(45) # Initial angle (radians)
# Air resistance parameters
Cd = 0.5
rho = 1.2 # Air density (kg/m³)
# Calculate initial x and y velocities
Vx = V_0 * np.cos(alpha)
Vy = V_0 * np.sin(alpha) - 0.5 * Cd * rho * V_0 ** 2 * np.sin(alpha) / 2
# Define the differential equations
def projectile_dynamics(state, t):
x, y, vx, vy = state
fx = vx
fy = -G * y - 0.5 * Cd * rho * V_0 ** 2 * np.sin(alpha)
return np.array([vx, vy, fx, fy])
# Define the time vector
t_range = np.linspace(0, 10, 100)
# Integrate the equations of motion
state = np.array([0, Vy, Vx, 0])
x, y, vx, vy = odeint(projectile_dynamics, state, t_range, dx=0.01)
# Plot the trajectory
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim([-5, 80])
ax.set_ylim([-15, 20])
ax.set_title('Trajectory of Projectile with Initial Speed V_0 = {:.1f} m/s and Angle alpha = {:.1f}°'.format(V_0, alpha * 180 / np.pi))
plt.show()
This code calculates the initial x and y velocities using the given initial speed and angle, and takes into account air resistance. The projectile_dynamics function defines the differential equations for the motion of the projectile. The odeint function from SciPy is used to integrate the equations over time. Finally, the resulting trajectory is plotted using Matplotlib.