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

Upload New File

parent 970cf57e
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 = 0
v_0 = 0
t_1 = 10
n = 20
g = 9.8
k = float(input("Ingrese el valor de k:"))
m = float(input("Ingrese el valor de m:"))
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
y = [y_0]
v = [v_0]
y_1 = y_0 + funcion(v_0, g, B)[0] * h
v_1 = v_0 + funcion(v_0, g, B)[1] * h
t = np.arange(t_0, t_1 + h, h)
for i in range(1, (n + 1)):
yi = y[i - 1] + funcion(v[i - 1], g, B)[0] * h
vi = v[i - 1] + funcion(v[i - 1], g, B)[1] * h
y.append(yi)
v.append(vi)
plt.figure()
plt.subplot(2, 1, 1)
plt.plot(t, y)
plt.xlabel('Tiempo')
plt.ylabel('Posición')
plt.title('Posición vs. Tiempo')
plt.subplot(2, 1, 2)
plt.plot(t, v)
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