{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cfd262a3-b18d-417a-a930-7ba5e8f48c57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\max \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 20 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 x_{3} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 4 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 48 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 28 \\\\\n",
       "\\end{array} \\\\\n",
       "x_{1}, x_{2}, x_{3} \\geq 0\n",
       "\\end{array}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\max \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 20 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 x_{3} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 4 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 48 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 28 \\\\\n",
       "\\end{array} \\\\\n",
       "x_{1}, x_{2}, x_{3} \\geq 0\n",
       "\\end{array}$"
      ],
      "text/plain": [
       "LP problem (use 'view(...)' or '%display typeset' for details)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle 720\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle 720$"
      ],
      "text/plain": [
       "720"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(0,\\,0,\\,24\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(0,\\,0,\\,24\\right)$"
      ],
      "text/plain": [
       "(0, 0, 24)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {}$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {\\texttt{El dual es:}}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {\\texttt{El dual es:}}$"
      ],
      "text/plain": [
       "dual"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\begin{array}{l}\n",
       "\\begin{array}{lcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 48 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 28 y_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 4 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 3 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 30 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 2 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 30 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2} \\geq 0\n",
       "\\end{array}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\begin{array}{l}\n",
       "\\begin{array}{lcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 48 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 28 y_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 4 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 3 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 30 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 2 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 30 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2} \\geq 0\n",
       "\\end{array}$"
      ],
      "text/plain": [
       "LP problem (use 'view(...)' or '%display typeset' for details)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle 720\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle 720$"
      ],
      "text/plain": [
       "720"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(15,\\,0\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(15,\\,0\\right)$"
      ],
      "text/plain": [
       "(15, 0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {}$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle {===================================}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle {===================================}$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 4 & 3 & 2 & 1 & 0 & 48 \\\\\n",
       "{\\color{green}{s}}_{2} & 1 & 2 & 1 & 0 & 1 & 28 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 20 & 30 & 30 & 0 & 0 & 0\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 4 & 3 & 2 & 1 & 0 & 48 \\\\\n",
       "{\\color{green}{s}}_{2} & 1 & 2 & 1 & 0 & 1 & 28 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 20 & 30 & 30 & 0 & 0 & 0\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2|rhs]\n",
       "[---+-------------------+---]\n",
       "[ s1|  4   3   2   1   0| 48]\n",
       "[ s2|  1   2   1   0   1| 28]\n",
       "[---+-------------------+---]\n",
       "[  Z| 20  30  30   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 2 , 2 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & \\frac{5}{2} & 0 & \\frac{1}{2} & 1 & -\\frac{3}{2} & 6 \\\\\n",
       "{x}_{2} & \\frac{1}{2} & 1 & \\frac{1}{2} & 0 & \\frac{1}{2} & 14 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 5 & 0 & 15 & 0 & -15 & 420\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & \\frac{5}{2} & 0 & \\frac{1}{2} & 1 & -\\frac{3}{2} & 6 \\\\\n",
       "{x}_{2} & \\frac{1}{2} & 1 & \\frac{1}{2} & 0 & \\frac{1}{2} & 14 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 5 & 0 & 15 & 0 & -15 & 420\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2| rhs]\n",
       "[----+------------------------+----]\n",
       "[  s1| 5/2    0  1/2    1 -3/2|   6]\n",
       "[  x2| 1/2    1  1/2    0  1/2|  14]\n",
       "[----+------------------------+----]\n",
       "[   Z|   5    0   15    0  -15| 420]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 1 , 3 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 5 & 0 & 1 & 2 & -3 & 12 \\\\\n",
       "{x}_{2} & -2 & 1 & 0 & -1 & 2 & 8 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -70 & 0 & 0 & -30 & 30 & 600\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 5 & 0 & 1 & 2 & -3 & 12 \\\\\n",
       "{x}_{2} & -2 & 1 & 0 & -1 & 2 & 8 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -70 & 0 & 0 & -30 & 30 & 600\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2|rhs]\n",
       "[---+-------------------+---]\n",
       "[ x3|  5   0   1   2  -3| 12]\n",
       "[ x2| -2   1   0  -1   2|  8]\n",
       "[---+-------------------+---]\n",
       "[  Z|-70   0   0 -30  30|600]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 2 , 5 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2| rhs]\n",
       "[----+------------------------+----]\n",
       "[  x3|   2  3/2    1  1/2    0|  24]\n",
       "[  s2|  -1  1/2    0 -1/2    1|   4]\n",
       "[----+------------------------+----]\n",
       "[   Z| -40  -15    0  -15    0| 720]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El problema es óptimo\n"
     ]
    }
   ],
   "source": [
    "tipo='max'  # max o min\n",
    "\n",
    "n=3 #  número de variables x's\n",
    "m=2 #  número de restricciones (distintas de las de signo)\n",
    "\n",
    "c=matrix(QQ,1,n,[20,30,30] )  # vector de costos\n",
    "\n",
    "A=matrix(QQ,m,n,[   # coeficientes de las variables x's\n",
    "[4,3,2],\n",
    "[1,2,1]\n",
    "])\n",
    "\n",
    "b=matrix(QQ,m,1,[48,28])  # vector de la derecha\n",
    "\n",
    "\n",
    "######################################################\n",
    "############### VARIABLES DE HOLGURA  ################\n",
    "\n",
    "\n",
    "h=matrix(ZZ,1,m,[1,1])  # variables de holgura: \n",
    "                            # Pon 1 si va sumando, \n",
    "                            # -1 si va restando y \n",
    "                            # 0 si no hay variable de holgura.\n",
    "t=matrix(ZZ,1,m,[0,0])\n",
    "\n",
    "colId=(4,5)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "####################################################################\n",
    "############  HASTA AQUÍ LOS DATOS  ################################\n",
    "####################################################################\n",
    "\n",
    "\n",
    "\n",
    "#load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')\n",
    "\n",
    "load('https://sage.unex.es/501708/simplex2023Auto.sage')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "515f33ba-9c94-48e6-a82b-b48d081f0d06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2| rhs]\n",
       "[----+------------------------+----]\n",
       "[  x3|   2  3/2    1  1/2    0|  24]\n",
       "[  s2|  -1  1/2    0 -1/2    1|   4]\n",
       "[----+------------------------+----]\n",
       "[   Z| -40  -15    0  -15    0| 720]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cambio(1,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b0eda70f-8974-46a8-8f29-42c4b34a390c",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|rr}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} & {b_1} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 & \\frac{1}{2} \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 & -\\frac{1}{2} \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720 & 15\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|rr}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} & {b_1} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 2 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & 24 & \\frac{1}{2} \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & \\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 4 & -\\frac{1}{2} \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -40 & -15 & 0 & -15 & 0 & 720 & 15\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2| rhs rhs1]\n",
       "[----+------------------------+---------]\n",
       "[  x3|   2  3/2    1  1/2    0|  24  1/2]\n",
       "[  s2|  -1  1/2    0 -1/2    1|   4 -1/2]\n",
       "[----+------------------------+---------]\n",
       "[   Z| -40  -15    0  -15    0| 720   15]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "bp=matrix(QQ,m,1,[1,0]); param1b(bp) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b3a75150-8b96-4f8e-9517-25fee992e325",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[40.000     NO     NO 30.000     NO]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cocientesD(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7cd99259-dc93-41be-9b63-6595190d0005",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\left(\\begin{array}{r|rrrrr|rr}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} & {b_1} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 1 & 2 & 1 & 0 & 1 & 28 & 0 \\\\\n",
       "{\\color{green}{s}}_{1} & 2 & -1 & 0 & 1 & -2 & -8 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -10 & -30 & 0 & 0 & -30 & 840 & 0\n",
       "\\end{array}\\right)\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\left(\\begin{array}{r|rrrrr|rr}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} & {b_1} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 1 & 2 & 1 & 0 & 1 & 28 & 0 \\\\\n",
       "{\\color{green}{s}}_{1} & 2 & -1 & 0 & 1 & -2 & -8 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & -10 & -30 & 0 & 0 & -30 & 840 & 0\n",
       "\\end{array}\\right)$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2| rhs rhs1]\n",
       "[----+------------------------+---------]\n",
       "[  x3|   1    2    1    0    1|  28    0]\n",
       "[  s1|   2   -1    0    1   -2|  -8    1]\n",
       "[----+------------------------+---------]\n",
       "[   Z| -10  -30    0    0  -30| 840    0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cambio(2,4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath",
   "language": "python",
   "name": "sagemath"
  },
  "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.13.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
