| Hosted by CoCalc | Download
Kernel: Python 2 (SageMath)
import numpy as np import pylab as py #Constants n = int t = 0 pi = 3.14159 dt = 0.01 B = 0.1 w0 = 2*np.pi dT = .25 fmax = 1 T = np.arange(1, 2.6, .5) print T #equations f0 = (fmax*dT)/T fn = ((2*fmax)/(np.pi*n))*sin((np.pi*dT)/T) A0 = f0/np.sqrt((w0**2)**2) An = fn/np.sqrt((((w0**2)-(n**2)*(w0**2))**2) + 4*(B**2)(n**2)(w0**2)) delta = arctan((2*B*n*w0)/((w0**2)-(n**2)*(w0**2))) #x = A*cos(n*w0*t - delta) A = zeros(5,4) for n in arange (0,7): if n==0: A[n, ] = A0 else: A[n, ] = An Delta = zeros(5) for n in arange (0,7): Delta[n] = delta print A def x (t ): if(t < 6): for n in arange (0,7): x = A[n, ]*cos(n*w0*t - Delta[n]) t = t + dt figure() plot(t, x) xlabel('t') ylabel('x(t)') title('T = T0') grid() xlim(0,6) ylim(-2.5,2.5) show()
[ 1. 1.5 2. 2.5]
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-21-806b2ab735c6> in <module>() 16 #equations 17 f0 = (fmax*dT)/T ---> 18 fn = ((2*fmax)/(np.pi*n))*sin((np.pi*dT)/T) 19 A0 = f0/np.sqrt((w0**2)**2) 20 An = fn/np.sqrt((((w0**2)-(n**2)*(w0**2))**2) + 4*(B**2)(n**2)(w0**2)) TypeError: unsupported operand type(s) for *: 'float' and 'type'
import numpy as np pi = 3.14 n = int t = 0 # np.arange(3) np.arange(1, 2.6, .5) # np.arange(10000,100000,10000) np.pi*n
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-22-300aeccd2056> in <module>() 7 np.arange(1, 2.6, .5) 8 # np.arange(10000,100000,10000) ----> 9 np.pi*n TypeError: unsupported operand type(s) for *: 'float' and 'type'