Skip to content

Instantly share code, notes, and snippets.

@Rhyssmcm
Created November 16, 2020 17:21
Show Gist options
  • Save Rhyssmcm/8f773f61563fd26c72ee3e23d24b1217 to your computer and use it in GitHub Desktop.
Save Rhyssmcm/8f773f61563fd26c72ee3e23d24b1217 to your computer and use it in GitHub Desktop.
(Q2)Derive the transfer function Gθ(s) using the force, F(s), as an input variable and the angle, X3(s), as the output variable. Derive the transfer function Gx(s) using the force, F(s), as an input variable and the horizontal position, X1(s).
import sympy as sym
m, ell, x1, x2, x3, x4, M, g, F, m = sym.symbols('m, ell, x1, x2, x3, x4, M, g, F, m')
# φ(F, x3, x4)
phi = 4*m*ell*x4**2*sym.sin(x3) + 4*F - 3*m*g*sym.sin(x3)*sym.cos(x3)
phi /= 4*(M+m) - 3*m*sym.cos(x3)**2
dphi_x3 = phi.diff(x3)
dphi_x4 = phi.diff(x4)
dphi_F = phi.diff(F)
psi = -3*(m*ell*x4**2*sym.sin(x3)*sym.cos(x3) + F*sym.cos(x3) - (M+m)*g*sym.sin(x3))
psi /= (4*(M+m) - 3*m*sym.cos(x3)**2)*ell
dpsi_x3 = psi.diff(x3)
dpsi_x4 = psi.diff(x4)
dpsi_F = psi.diff(F)
# Equilibrium point
Feq = 0
x3eq = 0
x4eq = 0
#------------------------------
# adding equilibrium to x1 and x2
#------------------------------
x1eq = 0
x2eq = 0
dphi_F_eq = dphi_F.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
dphi_x3_eq = dphi_x3.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
dphi_x4_eq = dphi_x4.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
dpsi_F_eq = dpsi_F.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
dpsi_x3_eq = dpsi_x3.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
dpsi_x4_eq = dpsi_x4.subs([(F, Feq), (x3, x3eq), (x4, x4eq)])
#Definitions of positive real constants
a = dphi_F_eq
b = -dphi_x3_eq
c = 3/(ell*(4*M + m))
d = 3*(M+m)*g/(ell*(4*M + m))
# ---------------------------------------------------------------------
a, b, c, d = sym.symbols('a:d')
s, t = sym.symbols('s, t')
#Derived Transfer fucntions
transfer_function_F_to_x3 = -c/(s**2 - d)
transfer_function_F_to_x1 = (a*(s**2 - d) + b*c)/(s**2)*(s**2-d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment