Modeling Engineered Systems - Northwestern Robotics

Lectures

Youtube playlist

  • Lecture 1: Everything Is The Same
  • Lecture 2: Modeling Components
  • Lecture 3: Newton’s Laws
  • Lecture 4: Euler Integration
  • Lecture 5: Exponential Solutions
  • Lecture 6: Superposition
  • Lecture 7: Newton’s Laws with Mass
  • Lecture 8: Newton’s Laws with Several Masses
  • Lecture 9: Imaginary Numbers & Euler’s Formula
    • \(e^{j \omega t}=\cos(\omega t) + j \sin(\omega t)\)
  • Lecture 10: Imaginary Numbers Continued
  • Lecture 11: Vector and Matrix Representation
  • Lecture 12: Vector Solutions to ODEs

  • Lecture 18: Modeling Electrical Components
  • Lecture 19: Kirchhoff’s Laws
  • Lecture 20: Kirchhoff’s Laws with Inductors
  • Lecture 21: Vector and Matrix Representation in Kirchhoff’s Laws
  • Lecture 22: Mechanical/Electrical Analogies
  • Lecture 23: Interpreting Mathematical Expressions as Physical Systems
  • Lecture 24: Everything Is The Same - Almost

Code

Simulate Spring-damper System using Euler Integration

import numpy as np
import matplotlib.pyplot as plt

"""
This program simulates a spring-damper system with the following ODE
x' + k/b*x = 0
"""

# define all govering system parameters:
t0 = 0.0
tf = 10.0
dt = 0.1
k = 1.0 # N/m
b = 1.0 # Ns/m
x0 = 0.5 # m

# create arrays for x and time:
tvec = np.arange(t0, tf+dt, dt)
xvec = np.zeros(len(tvec))
xvec[0] = x0

# run the euler integration
for i in range(len(xvec)-1):
    xvec[i+1] = xvec[i] + -k/b*dt*xvec[i]
    
# plot the results
plt.plot(tvec, xvec, lw=2)
plt.xlabel('time [sec]')
plt.ylabel('x [m]')
plt.grid(True)
plt.show()
plt.close()
plt.clf()
plt.cla()