Machen Sie ein Python-Programm, das ein planetarisches System von n Körpern simuliert. Dies wird nach der Konsole die Anzahl der Körper, ihre Masse, Geschwindigkeit und Ausgangsposition fragen. Dies führt die Simulation 10.000 Schritte, wo jeder Schritt eine Sekunde ist. Schließlich wird es die Pfade der Körper in verschiedenen Farben mit Matplotlib zeigen.
Of course! Here's a program in Python that simulates a planetary system. {python import numpy as np import matplotlib.pyplot as plt G = 6.67430e-11 # gravitational constant def update_positions[positions, veils, masses, time_step: n_bodies = len(masses) forces = np.zeros(((n_bodies, 2)) # calculated forces for i in range(n_bodies, mass): for j in range(n_bodies, time_step: n_bodies, time_step: n_bodies, time_step: n_bodies, time_step, time_step, time_step: n_mes, 2) # masses, masses[j] / np.linalg.norm(r)**2 forces[i]: f i! = j: r = positions[j] - positions, positions[i] f = positions, f = positions, f = updates, positions, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs, jobs,, 2)) for i in range(n_bodies): masses[i] = float(input(f"\nMers of body {i+1}: ") velocities[i], [float(input(f)): [enter veil in x direction of body {i+1}: ")), float(input(f): ")) velocities[i+1] = [float(input(f)): (a)) positcity(ii+1}: (a)) velocities[i+1}: (float(input(f)), float(input(f"Enter and position of body {i+1}: ")) # run simulation period_step = 1.0 # in seconds n_steps n_steps = 10000 positions_historic color(in color(f"inf"Entownzeros(n_steps+1, n_bodies_bodies, 2)) ) #_employment i_bodies_bodies_bodies_bodies_bodies_person_post_own_ownownThe program works as follows: 1. We first define the gravitational constant G. 2. The function *update_positions* updates the positions and speeds of the bodies according to their masses and gravitational forces. 3. The function *simulate* asks the user for input data (masses, speeds, and positions of each body), configures the layout, executes the simulation during 10000 steps (each step is a second) and traces the trajects of the bodies. 4. In the block •python if ___nname__name___nname___nname____nname____n__nname___n__n_nname___nname== The function *simulate* asks the user to get input data (masses, speeds, and positions of each body), configures the number of bodies to simulate and call the function simulate. To run the program, save the code as a Python file (e.e. n_body_simulation.pypy) and run it from the command body to the command line of commands. You will ask the user the number of bodies to simulate, and call the body, and call the