{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Problem 3.g\n", "\n", "Use the following code to simulate the system. Plug in your solutions for $A_{CL}$ and $B_{CL}$ and your values of K.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "SIM_LENGTH = 100\n", "\n", "# YOUR CODE HERE#\n", "k1 = \n", "k2 = \n", "Ts = .1\n", "mu = -.2\n", "\n", "A = np.matrix([[1, Ts], [0, 2]])\n", "B = np.matrix([[.01], [.2]])\n", "K = np.matrix([k1, k2])\n", "\n", "x = np.zeros((2,SIM_LENGTH))\n", "xd = np.zeros((2,SIM_LENGTH))\n", "xd[0,:] = np.linspace(0 , SIM_LENGTH*Ts, SIM_LENGTH)\n", "xd[1,:] = np.ones(SIM_LENGTH)\n", "\n", "# YOUR CODE HERE #\n", "ACL = \n", "BCL = \n", "\n", "\n", "for i in range(0,SIM_LENGTH-1):\n", " x[:,i+1] = list(np.add(np.dot(ACL, np.matrix(x[:,i]).T), np.dot(BCL,xd[:,i]).T))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now check your eigenvalues to make sure that your system will be stable." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('ACL:')\n", "print(ACL)\n", "e = np.linalg.eig(ACL)\n", "print('eigenvalues:')\n", "print(e[0])\n", "print('eigenvectors:')\n", "print(e[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, let's look at the simultion and see how quickly it converges." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.plot(x[0,:].T)\n", "plt.plot(xd[0,:].T)\n", "plt.xlim([0,SIM_LENGTH-2])\n", "plt.legend(['simulation', 'desired'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.plot(x[1,:].T)\n", "plt.plot(xd[1,:].T)\n", "plt.xlim([0,SIM_LENGTH-2])\n", "plt.legend(['simulation', 'desired'])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }