"""------------------------------------------ EJERCICIO 3 ------------------------------------------------ % Dependencias: Para que este script se ejecute correctamente tanto en Windows como en Linux o MacOS se necesita tener instaladas las siguientes librerías: - matplotlib - numpy - sympy Si se desea ejecutar en la herramienta online "Jupyter Notebook", solo bastará con copiar el script dentro de una "Cell" y dar click en el boton Run/Ejecutar que se encuentra en dicha plataforma Instalación de librerías (Win, Linux o MacOS): En caso de no contar con alguna o todas las librerías necesarias de se deberan ejecutar en la terminal/CMD los siguientes comandos como administrador en el siguiente orden: 1. Instalar el gestor de paquetes de python pip: python -m pip install -U pip 2. Instalar Matplotlib: python -m pip install -U matplotlib 3. Instalar Numpy: pip install numpy 4. Instalar Sympy: pip install sympy --------------------------------------------------------------------------------------------------------------------""" import numpy as np import matplotlib.pyplot as plt import sympy as sp t = sp.symbols('t') i_t = sp.Piecewise ((-t + 9e-3, t <= 3e-3), (250*(t**2)-(5/2)*t + (9/800), ((t > 3e-3) & (t <= 11e-3))), (14e-3, ((t > 11e-3) & (t <= 14e-3))), (-t + 28e-3, t > 14e-3)) tt = np.linspace(-3e-3, 20e-3, 1000) i = sp.lambdify(t, i_t) I_t = sp.diff(i_t, t) plt.figure("Ejercicio 3", figsize = (13,5)) plt.subplot(1,2,1) plt.plot(tt, i(tt), linewidth = 1.5, color = 'red') plt.title("Corriente eléctrica") plt.ylabel("i [A]") plt.xlabel("t [s]") plt.xlim(-2e-3, 20e-3) plt.grid(which ='major', color = '#666666') plt.minorticks_on() plt.grid(which = 'minor', color = '#999999', alpha = 0.2) v_t = 45e-3*I_t v = sp.lambdify(t, v_t) plt.subplot(1,2,2) plt.plot(tt, v(tt), linewidth = 2, color = 'blue') plt.title("Voltaje") plt.ylabel("v [V]") plt.xlabel("t [s]") plt.ylim(-60e-3, 140e-3) plt.xlim(-2e-3, 20e-3) plt.grid(which ='major', color = '#666666') plt.minorticks_on() plt.grid(which = 'minor', color = '#999999', alpha = 0.2) plt.show() plt.figure("Ejercicio 3", figsize = (13,5)) p_t = -i_t*v_t p = sp.lambdify(t, p_t) plt.subplot(1,2,1) plt.plot(tt, p(tt), linewidth = 2, color = 'green') plt.title("Potencia") plt.ylabel("p [W]") plt.xlabel("t [s]") plt.ylim(-2e-3, 7e-4) plt.xlim(-2e-3, 20e-3) plt.grid(which ='major', color = '#666666') plt.minorticks_on() plt.grid(which = 'minor', color = '#999999', alpha = 0.2) E_t = sp.integrate(p_t, t) E = sp.lambdify(t, E_t) plt.subplot(1,2,2) plt.plot(tt, E(tt), linewidth = 2, color = 'maroon') plt.title("Energía") plt.ylabel("E [J]") plt.xlabel("t [s]") plt.ylim(-3e-6, 1.5e-6) plt.xlim(-2e-3, 20e-3) plt.grid(which ='major', color = '#666666') plt.minorticks_on() plt.grid(which = 'minor', color = '#999999', alpha = 0.2) plt.show()