{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vecs import *\n",
    "from sympy import *\n",
    "import random\n",
    "init_printing(use_unicode=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Consider the system:\n",
    "\n",
    "$$x + 2y + z = 2$$\n",
    "$$-2x - 4y - 2z = -4$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "M = Matrix([\n",
    "    [1, 2, 1, 2],\n",
    "    [-2, -4, -2, -4]\n",
    "])\n",
    "display(M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "M.rref()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v = lambda y, z: Vector(2 - 2 * y - z, y, z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v1 = v(y = 1, z = 2)\n",
    "display(v1)\n",
    "\n",
    "v2 = v(y = -1, z = 2)\n",
    "display(v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display(v1 - v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "marks = []\n",
    "random.seed(1)\n",
    "\n",
    "p = v(y = 3, z = -1)\n",
    "\n",
    "for i in range(100):\n",
    "    v1 = v(y = random.random() * 5 - 2.5,\n",
    "           z = random.random() * 5 - 2.5)\n",
    "    \n",
    "    v2 = v(y = random.random() * 5 - 2.5,\n",
    "           z = random.random() * 5 - 2.5)\n",
    "    \n",
    "    marks.append(mark(v1))\n",
    "    marks.append(mark(v2))\n",
    "    \n",
    "    v3 = v1 - v2\n",
    "    marks.append(mark(p + v3, color='red'))\n",
    "\n",
    "\n",
    "draw(\n",
    "    marks,\n",
    "#     arrow(v1, color='blue'),\n",
    "#     arrow(v2, color='gray'),\n",
    "#     arrow(-1 * v2, start=v1, color='green')\n",
    ")"
   ]
  },
  {
   "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.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
