def laplace_transform_comparison(fTilde, F_of_s): frequency_vector = [0.1, 1, 10, 100] laplace_transform_fTilde = [float(0) for x in range(0,len(fTilde))] for i in range(0,len(fTilde)): laplace_transform_fTilde[i] = laplace_transform(fTilde[i], t, s) print(laplace_transform_fTilde[0]) print(laplace_transform_fTilde[0].evalf(subs={s:1}))
Python Sympy is a package that has symbolic math functions. A few of the notable ones that are useful for this material are the: a. Laplace transform b. Inverse Laplace transform c. Partial Fraction expansion d. Polynomial expansion e. Polynomial roots """ import sympy as sym from sympy.abc import s,t,x,y,z from sympy.integrals import laplace_transform from sympy.integrals import inverse_laplace_transform # Laplace transform (t->s) U = laplace_transform(5*t, t, s) print('U') print(U[0]) # Result: 5/s**2 # Inverse Laplace transform (s->t) X = inverse_laplace_transform(U[0],s,t) print('X') print(X) # Result: 5*t*Heaviside(t) # Function F = 5*(s+1)/(s+3)**2 print('F') print(F) # Result: (5*s + 5)/(s + 3)**2
#print('y1:',y1) a = int(input('enter the coefficient of second deri of y:')) b = int(input('enter the coefficient of first deri of y:')) c = int(input('enter the coefficient of y:')) f = (input('enter the RHS function:')) d = int(input('enter the value of y(0):')) e = int(input('enter the value of Dy(0):')) f = sympify(f) y1 = diff(y, t) y2 = diff(y1, t) eq = a * y2 + b * y1 + c * y - f print('equation:', eq) print(' ') eqn = laplace_transform(eq, t, s) print('after laplace equation:', eqn) print(' ') eqn = sympify(eqn) #eqn=eqn.subs(t,0) #eqn=eqn.subs(y(0),d) print('after replacing:', eqn) print(' ') eqn = eqn.subs(sympify('LaplaceTransform(y(t), t, s)'), Y) print('after replacing:', eqn) print(' ') eqn = eqn.subs(sympify(y1), e)
#%% from sympy.integrals import laplace_transform from sympy import * from sympy.abc import t, s Tau = 1.0 U = laplace_transform(Heaviside(t), t, s) print(f"The Laplace transform of the unit step function, u(t) is:{U[0]}") # Use U[0] becaie the result of the laplace_transform function is a tuple. h = -1 / Tau * exp(-t / Tau) print(f"The impulse response of a High Pass filter with Tau={Tau} is: {h}") H = laplace_transform(h, t, s) print(f"The Laplace transform of a High Pass filter with Tau={Tau} is: {h}") Y = U[0] * H[0] print( f"The frequency response of a unit step input into a High Pass filter with Tau={Tau} is {Y}." ) Y_PF = apart(Y) print( f"The partial fraction expansion of the frequency response of a unit step input into a High Pass filter with Tau={Tau} is: {Y_PF}" ) y = inverse_laplace_transform(Y_PF, s, t).evalf().simplify() print(f"Time domain step reponse of a High Pass filter with Tau={Tau} is {y}") plot(y + 1, (t, 0, 5 * Tau), title='Step Response High Pass', xlabel='time(s)', ylabel='Step response') #%% from sympy.integrals import laplace_transform from sympy import *
def answers(): global Answ1, Answ2, Answ3, Answ4, Answ5 s, t, x, y, z = symbols('s t x y z') A2.delete(0, END) if E1.get() == '' or E1.get() == 0: Answ1 = '' else: if E1.index(0) == '-': Answ1 = sympify(laplace_transform(E1.get(), t, s, noconds=True)) sig = '-' Answ1s = sig + Answ1 A2.insert(0, Answ1s) else: Answ1 = sympify(laplace_transform(E1.get(), t, s, noconds=True)) A2.insert(0, Answ1) if E2.get() == '' or E2.get() == 0: Answ2 = '' else: if E2.index(0) == '-': Answ2 = sympify(laplace_transform(E2.get(), t, s, noconds=True)) sig = ' - ' Answ2s = sig + Answ2 A2.insert(END, Answ2s) else: Answ2 = sympify(laplace_transform(E2.get(), t, s, noconds=True)) A2.insert(END, ' + ') A2.insert(END, Answ2) if E3.get() == '' or E3.get() == 0: Answ3 = '' else: if E3.index(0) == '-': Answ3 = sympify(laplace_transform(E3.get(), t, s, noconds=True)) sig = ' - ' Answ3s = sig + Answ3 A2.insert(END, Answ3s) else: Answ3 = sympify(laplace_transform(E3.get(), t, s, noconds=True)) A2.insert(END, ' + ') A2.insert(END, Answ3) if E4.get() == '' or E4.get() == 0: Answ4 = '' else: if E4.index(0) == '-': Answ4 = sympify(laplace_transform(E4.get(), t, s, noconds=True)) sig = ' - ' Answ4s = sig + Answ4 A2.insert(END, Answ4s) else: Answ4 = sympify(laplace_transform(E4.get(), t, s, noconds=True)) A2.insert(END, ' + ') A2.insert(END, Answ4) if E5.get() == '' or E5.get() == 0: Answ5 = '' else: if E5.index(0) == '-': Answ5 = sympify(laplace_transform(E5.get(), t, s, noconds=True)) sig = ' - ' Answ5s = sig + Answ5 A2.insert(END, Answ5s) else: Answ5 = sympify(laplace_transform(E5.get(), t, s, noconds=True)) A2.insert(END, ' + ') A2.insert(END, Answ5) A2.config(font=("Helvetica", 15)) A2.config(state=DISABLED)
laplace.subs(s, s - a) # In[15]: import numpy as np from sympy.integrals import laplace_transform from sympy.abc import t, s, a, b # In[16]: f = cos(t) listu = [] for i in np.arange(0, 8 * np.pi, 0.2): listu.append(f.subs(t, i)) pt.plot(np.arange(0, 8 * np.pi, 0.2), listu, label="f(t) graph") g = laplace_transform(f, t, s) g = g[0] listy = [] #g(s) values for i in np.arange(0, 8 * np.pi, 0.2): listy.append(g.subs(s, i)) pt.plot(np.arange(0, 8 * np.pi, 0.2), listy, label="f(s) graph") pt.legend() # In[17]: f = exp(a * t) * sin(b * t) #can solve this easily by first shifting property #take f1 f1 = sin(b * t) g1 = laplace_transform(f1, t, s) g1 = g1[0]
def laplace_carson(f, t, s): l = laplace_transform(f, t, s) l_c = sy.simplify(s * l[0]) return l_c
from tool import * from sympy import * from sympy.abc import x, k, f from sympy.integrals import laplace_transform, fourier_transform f1 = fourier_transform(exp(-x**2), x, k) print(f1) f1 = laplace_transform(sin(x), x, f) print(f1) # help(laplace_transform) help(fourier_series)
a=[] ti = np.linspace(0,30000,25) #print ti for i in range(0,25): a.append(Heaviside(ti[i])) #print a #plotting input function plt.figure(1) plt.plot(ti, a) plt.title('Input Function') plt.xlabel('Time') #plt.ylabel('') plt.show() Input_func_laplace = laplace_transform(Heaviside(t).rewrite(exp),t,s) #print Input_func_laplace[0] #transfer func as given in paper Trans_func = k*((tau_p*s+1)/(tau_d*s+1)) Output_func_laplace = Input_func_laplace[0]*Trans_func print Output_func_laplace '''c=[] plt.figure(3) for i in range(0,25): c.append(Output_func_laplace.subs(s,ti[i])) plt.plot(ti,c) plt.title('Laplace Function curve') plt.show()'''