{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "# Sección 4.3\n", "Emplearémos sympy para mostrar las composiciones de dos funciones F y G dadas." ], "metadata": { "id": "qGHeQyka-zvr" } }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 76 }, "id": "opW6A2_g4Lzx", "outputId": "7a519c00-ca54-468f-eb92-b8cdd9f9ee46" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "f(g(x)):\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "sqrt(1 - 1/x**2)" ], "text/latex": "$\\displaystyle \\sqrt{1 - \\frac{1}{x^{2}}}$" }, "metadata": {} } ], "source": [ "#import sympy as sym\n", "from sympy import symbols, sqrt\n", "\n", "x = symbols('x')\n", "\n", "# 1. Definimos las expresiones de las funciones\n", "f = sqrt(1 - x**2)\n", "g = 1 / x\n", "\n", "# 2. Calculamos las composiciones usando .subs()\n", "# fog significa f(g(x)): En 'f', sustituimos la 'x' por 'g'\n", "fog = f.subs(x, g)\n", "\n", "# gof significa g(f(x)): En 'g', sustituimos la 'x' por 'f'\n", "gof = g.subs(x, f)\n", "\n", "# 3. Mostramos los fog:\n", "print(f\"f(g(x)):\")\n", "display(fog)\n" ] }, { "cell_type": "code", "source": [ "# Ahora mostramos gof\n", "print(f\"g(f(x)):\")\n", "display(gof)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 72 }, "id": "iu9i4iDY5LpA", "outputId": "dc9e3ffc-c37f-4823-c7de-9c576777e823" }, "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "g(f(x)):\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "1/sqrt(1 - x**2)" ], "text/latex": "$\\displaystyle \\frac{1}{\\sqrt{1 - x^{2}}}$" }, "metadata": {} } ] } ] }