import math
import matplotlib.pyplot as plt
import numpy as np

# Datos
ensayo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
theta = [35.5, 32.2, 35.2, 35.5, 36.0, 32.7, 31.7, 34.2, 31.9, 31.5]

# Cálculo de μ = tan(θ) convirtiendo grados → radianes
mu = [math.tan(math.radians(ang)) for ang in theta]

# Convertimos mu a array para cálculos estadísticos
mu_array = np.array(mu)

# Cálculos estadísticos
mu_promedio = np.mean(mu_array)
mu_std = np.std(mu_array, ddof=1)   # ddof=1 → desviación estándar muestral
error_porcentual = (mu_std / mu_promedio) * 100

# Mostrar tabla
print("="*48)
print(f"{'Ensayo':<15}{'Ángulo (°)':<20}{'μ_s = tan(θ)'}")
print("="*48)
for e, ang, m in zip(ensayo, theta, mu):
    print(f"{e:<15}{ang:<20.1f}{m:.5f}")
print("="*48)

# PROMEDIO Y DESVIACIÓN ESTÁNDAR
print(f"Coeficiente μ_s estimado : {mu_promedio:.5f} ± {mu_std:.5f}")
print(f"Error porcentual         : {error_porcentual:.2f}%")
print("="*48)


# ---------  GRÁFICO  ---------
plt.figure(figsize=(9,5))
plt.scatter(ensayo, mu, color='red', s=50)
plt.xticks(ensayo, fontsize=14)
plt.axhline(mu_promedio, color='blue', linestyle='--', label=f"μ = {mu_promedio:.2f} ± {mu_std:.2f}")

# Franja de error (zona sombreada)
x_min, x_max = plt.xlim()   # obtener límites actuales del eje X
plt.fill_between(
    [x_min, x_max],
    mu_promedio - mu_std,
    mu_promedio + mu_std,
    color='blue',
    alpha=0.2
)

plt.xlabel("Ensayo", fontsize=16)
plt.ylabel("Coeficiente μ_s", fontsize=16)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.grid(True)

# ⭐ Leyenda en la parte superior derecha
plt.legend(fontsize=14, loc='upper right')
plt.tight_layout()
plt.show()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: