{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matemáticas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pip install"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: sympy in c:\\users\\lord_fulgi\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (1.13.3)\n",
      "Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\lord_fulgi\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from sympy) (1.3.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip is available: 24.0 -> 24.2\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    }
   ],
   "source": [
    "pip install sympy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sympy as sp\n",
    "from sympy import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calculadora"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Funciones:\n",
    "\n",
    "    ·ddx(f,n) o ddy(f,n); derivadas de orden n\n",
    "    ·intdx(f) o intdy(f); integrales\n",
    "    ·solvex(a,b) o solvey(a,b); resuelve ecuaciones algebraicas del tipo a = b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 1$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Derivadas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funciones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ddx(f, n):\n",
    "    x = symbols('x')\n",
    "    derivada = diff(f, x, n)\n",
    "    \n",
    "    return derivada\n",
    "\n",
    "def ddy(f, n):\n",
    "    y = symbols('y')\n",
    "    derivada = diff(f, y, n)\n",
    "    \n",
    "    return derivada"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ejemplo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 3 x^{2} + 4 x + 5$"
      ],
      "text/plain": [
       "3*x**2 + 4*x + 5"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = sp.symbols('x')\n",
    "f = x**3 + 2*x**2 + 5*x\n",
    "\n",
    "derivada = sp.diff(f, x)\n",
    "\n",
    "derivada"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integrales"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funciones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def intdx(f):\n",
    "    x = sp.symbols('x')\n",
    "    integral = sp.integrate(f, x)\n",
    "    \n",
    "    return integral\n",
    "\n",
    "def intdy(f):\n",
    "    y = sp.symbols('y')\n",
    "    integral = sp.integrate(f, y)\n",
    "    \n",
    "    return integral"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ejemplo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{x^{4}}{4} + \\frac{2 x^{3}}{3}$"
      ],
      "text/plain": [
       "x**4/4 + 2*x**3/3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = sp.symbols('x')\n",
    "f = x**3 +2*x**2\n",
    "\n",
    "integral = sp.integrate(f, x)\n",
    "\n",
    "integral"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Resolver Ecuaciones Algebraicas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funciones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def solvex(a,b):\n",
    "    ecuacion = sp.Eq(a, b)\n",
    "    solucion = sp.solve(ecuacion, x)\n",
    "    \n",
    "    return solucion\n",
    "\n",
    "def solvey(a,b):\n",
    "    ecuacion = sp.Eq(a, b)\n",
    "    solucion = sp.solve(ecuacion, y)\n",
    "    \n",
    "    return solucion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ejemplo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-3, 0]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#   Ecuación x**2 + 3x = 0\n",
    "ecuacion = sp.Eq(x**2 + 3*x, 0)\n",
    "\n",
    "solucion = sp.solve(ecuacion, x)\n",
    "\n",
    "solucion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Resolver Ecuaciones Diferenciales"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funciones"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ejemplo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle y{\\left(x \\right)} = C_{1} e^{- x} + C_{2} e^{x}$"
      ],
      "text/plain": [
       "Eq(y(x), C1*exp(-x) + C2*exp(x))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#   Definir una función dependiente de x\n",
    "y = sp.Function('y')\n",
    "\n",
    "ecuacion_dif = sp.Eq(y(x).diff(x, 2) - y(x), 0)\n",
    "solucion_ed = sp.dsolve(ecuacion_dif, y(x))\n",
    "\n",
    "solucion_ed"
   ]
  }
 ],
 "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
