Skip to content
Snippets Groups Projects
Commit 4074129e authored by Carlos Mario Alvarez Lizcano's avatar Carlos Mario Alvarez Lizcano
Browse files

Upload New File

parent 218b16f1
No related branches found
No related tags found
No related merge requests found
import numpy as np
import matplotlib.pyplot as plt
from time import perf_counter_ns
t_0 = 0
y_0 = float(input("Ingrese la altura a la que se deja caer: "))
v_0 = 0
t_1 = 10
n = 20
g = 9.8
k = float(input("Ingrese el valor de la resistencia del medio: "))
m = float(input("Ingrese el valor de la masa: "))
B = k / m
ti_inicial = perf_counter_ns()
def funcion(v, g, B):
dydt = v
dvdt = g - B * v
return dydt, dvdt
h = (t_1 - t_0) / n
t_values = np.linspace(t_0, t_1, n+1)
y_values = [y_0]
v_values = [v_0]
for i in range(n):
t = t_values[i]
y = y_values[i]
v = v_values[i]
k1y, k1v = funcion(v, g, B)
k2y, k2v = funcion(v + h / 2 * k1v, g, B)
k3y, k3v = funcion(v + h / 2 * k2v, g, B)
k4y, k4v = funcion(v + h * k3v, g, B)
pendiente_y = (k1y + 2 * k2y + 2 * k3y + k4y) / 6
pendiente_v = (k1v + 2 * k2v + 2 * k3v + k4v) / 6
y_new = y + h * pendiente_y
v_new = v + h * pendiente_v
y_values.append(y_new)
v_values.append(v_new)
plt.figure()
plt.subplot(2, 1, 1)
plt.plot(t_values, y_values)
plt.xlabel('Tiempo')
plt.ylabel('Posición')
plt.title('Posición vs. Tiempo')
plt.subplot(2, 1, 2)
plt.plot(t_values, v_values)
plt.xlabel('Tiempo')
plt.ylabel('Velocidad')
plt.title('Velocidad vs. Tiempo')
plt.tight_layout()
plt.show()
ti_final = perf_counter_ns()
tiempo_ejecucion = ti_final - ti_inicial
print("Tiempo de ejecución (nanosegundos):", tiempo_ejecucion)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment