# -*- coding: utf-8 -*- """ Created on Sun Jun 8 15:38:17 2014 @author: lba """ #import pdb from numpy import * #from matplotlib.pyplot import plot K = 100 # Electromagnetic torque coefficient D = 2 # Friction coefficient J = 4 # Moment of inertia dt = .001 betat = 0 # Initial position of the rotor dbetat = 0 # Initial angular speed of the rotor beta = zeros(len(t)) dbeta = zeros(len(t)) i = zeros(len(t)) beta[0] = betat dbeta[0] = dbetat #pdb.set_trace() for j in arange(len(t)-1) + 1: it = A * betat + B * dbetat + alpha[j-1] # i(t) i[j-1] = it d2betat = (K * it - D * dbetat) / J dbetat = dbetat + d2betat * dt betat = betat + dbetat * dt beta[j] = betat dbeta[j] = dbetat it = A * betat + B * dbetat + alpha[j-1] i[-1:] = it # Fill the last value of i, which was not filled in the loop