Introduction

     Projectile motion refers to the motion of an object projected into the air, influenced only by gravity. This Python script simulates and displays the trajectory of a projectile given its initial velocity and launch angle.  
    Below Python code is an implementation of the Euler method. The Euler method is a numerical technique for solving ordinary differential equations (ODEs) with a given initial value. In this case, it appears to be applied to the projectile motion of a particle under the influence of gravity.

How to use

1. Run the script and provide the initial velocity, launch angle, total time, and time step as prompted.
2. The program will then simulate the projectile motion and print the state (time, velocities, and positions) at each time step.
3. The final state of the projectile is displayed once the simulation is complete.

Code

    
     
        from math import *

        v0, ang = map(float, input('Enter the initial Velocity & Angle of projection: ').split())
        tf = float(input('Enter the time: '))
        h = float(input('Enter the time step: '))
        
        ang = ang * pi / 180
        ax = 0.0
        ay = -9.8
        vx = v0 * cos(ang)
        vy = v0 * sin(ang)
        x = y = t = 0
        
        print('Time   X-Velocity   Y-Velocity   X-Position   Y-Position')
        
        while t <= tf:
            print('%6.3f %12.3f %12.3f %12.3f %12.3f' % (t, vx, vy, x, y))
            vx = vx + ax * h
            vy = vy + ay * h
            x = x + vx * h
            y = y + vy * h
            t = t + h
        
        print('%6.3f %12.3f %12.3f %12.3f %12.3f' % (t, vx, vy, x, y))
        
       
       
     


Output


    Enter the initial Velocity & Angle of projection: 10 60
    Enter the time: 0.6
    Enter the time step: 0.2
    Time   X-Velocity   Y-Velocity   X-Position   Y-Position
    0.000        5.000        8.660        0.000        0.000
    0.200        5.000        6.700        1.000        1.340
    0.400        5.000        4.740        2.000        2.288
    0.600        5.000        2.780        3.000        2.844
       



Understanding the output

  • Time: The time elapsed during the simulation.
  • X-Velocity: The horizontal component of velocity.
  • Y-Velocity: The vertical component of velocity.
  • X-Position: The horizontal position.
  • Y-Position: The vertical position.
This script uses numerical integration to update the projectile's state over time, providing a simple yet insightful visualization of projectile motion.

Feel free to experiment with different initial conditions to observe how they impact the trajectory. This simulation serves as a foundation for understanding more complex physics simulations in Python.

Conclusion

     In conclusion, the Euler method is a fundamental numerical technique employed for approximating solutions to ordinary differential equations (ODEs) by iteratively updating values based on derivatives. The provided Python code demonstrates the application of the Euler method to simulate the projectile motion of a particle subjected to gravity.