{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def plot_linear_eqns(xs, y1s, label1, y2s, label2):\n",
    "    fig = plt.figure()\n",
    "    ax = fig.add_subplot(1, 1, 1)\n",
    "\n",
    "    ax.spines['left'].set_position(('data', 0))\n",
    "    ax.spines['right'].set_color('none')\n",
    "    ax.spines['bottom'].set_position(('data', 0))\n",
    "    ax.spines['top'].set_color('none')\n",
    "\n",
    "    plt.plot(xs, y1s, label=label1)\n",
    "    plt.plot(xs, y2s, label=label2)\n",
    "    plt.legend(loc='upper right')\n",
    "    plt.show()    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "xs  = np.linspace(-1, 5, 100)\n",
    "y1s = np.array([-2*x + 8 for x in xs])\n",
    "y2s = np.array([(1/3)*x + 1 for x in xs])\n",
    "\n",
    "plot_linear_eqns(xs, y1s, '2x + y = 8', y2s, 'x - 3y = -3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[2,  1],\n",
    "              [1, -3]])\n",
    "b = np.array([8, -3])\n",
    "x = np.linalg.solve(A, b)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xs  = np.linspace(-1, 5, 100)\n",
    "y1s = np.array([(16 - 4*x)/2 for x in xs])\n",
    "y2s = np.array([(15 - 6*x)/3 for x in xs])\n",
    "\n",
    "plot_linear_eqns(xs, y1s, '4x + 2y = 16', y2s, '6x + 3y = 15')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xs  = np.linspace(-1, 5, 100)\n",
    "y1s = np.array([(16 - 4*x)/2 for x in xs])\n",
    "y2s = np.array([(24 - 6*x)/3 for x in xs])\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(1, 1, 1)\n",
    "\n",
    "ax.spines['left'].set_position(('data', 0))\n",
    "ax.spines['right'].set_color('none')\n",
    "ax.spines['bottom'].set_position(('data', 0))\n",
    "ax.spines['top'].set_color('none')\n",
    "\n",
    "plt.plot(xs, y1s, '-r', label='4x + 2y = 16')\n",
    "plt.plot(xs, y2s, ':g', label='6x + 3y = 24')\n",
    "plt.legend(loc='upper right')\n",
    "plt.show()    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
