alchemyst/Skogestad-Python

View on GitHub
reproductions/Example/Example_05_13.ipynb

Summary

Maintainability
Test Coverage
{
  "cells": [
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "\n",
        "from robustcontrol.utilsplot import  step_response_plot\n",
        "from robustcontrol.utils import feedback, tf\n",
        "\n",
        "\n",
        "s = tf([1,0], 1)\n",
        "\n",
        "Kd = 0.5\n",
        "\n",
        "G = 5/((10*s + 1)*(s - 1))\n",
        "Gd = Kd/((s + 1)*(0.2*s + 1))\n",
        "K = 0.04/s*((10*s + 1)**2)/((0.1*s + 1)**2)\n",
        "\n",
        "L = G * K\n",
        "\n",
        "# Transfer function between disturbance and output y\n",
        "S = feedback(1, L) * Gd\n",
        "\n",
        "# Transfer function between disturbance and controller input u\n",
        "Gu = -S * K\n",
        "\n",
        "plt.figure('Figure 5.16 (a)')\n",
        "\n",
        "plt.subplot(1, 2, 1)\n",
        "w = np.logspace(-2, 1, 1000)\n",
        "wi = w*1j\n",
        "plt.loglog(w, np.abs(G(wi)))\n",
        "plt.loglog(w, np.abs(Gd(wi)))\n",
        "plt.axhline(1, color='black', linestyle=':')\n",
        "plt.title('(a) $|G|$ & $|G_d|$ with $k_d$=0.5')\n",
        "plt.xlabel('Frequency [rad/s]')\n",
        "plt.ylabel('Magnitude')\n",
        "plt.legend(('$|G|$', '$|G_d|$'), loc=1)\n",
        "\n",
        "plt.subplot(1, 2, 2)\n",
        "step_response_plot(S, Gu, t_end=10, constraint=1)  # TODO y(t)const is not yet correct\n",
        "plt.title('(b) Response to step in disturbance ($k_d=0.5$)')\n",
        "\n",
        "plt.show()\n"
      ],
      "outputs": [],
      "execution_count": null
    }
  ],
  "metadata": {
    "anaconda-cloud": {},
    "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.6.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 1
}