{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## How not to feel bored – 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Библиотека для символьных вычислений sympy: продолжение\n", "\n", "### Интегралы в sympy " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Для начала импортируем библиотеку (если ещё не работали с sympy, см. обзор [здесь](https://github.com/allatambov/py-icef/blob/master/add/sympy-1.ipynb)) и определим символы для переменных, с которыми будем работать." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from sympy import *\n", "x, y = symbols(\"x y\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Найдём неопределённый интеграл от какой-нибудь функции. Зададим саму функцию и выведем её в красивом свёрстанном виде:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAqBAMAAACq4N3gAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMt0Qq5nNdrvvIolEZlSFnHVmAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAqUlEQVQoFWNgAAEhAzAFIphd8xEcBob6QcXxmK9SAHcpPRj/EeADFexbGtYIN4XLgWH/ARiPxYCBcwKMw/mZgeUXjMOiwMDyEcYB0kwfGMxLDHc/AAvJFzAEsLuzKoA5qgy8C9h/sVwAcVgDGBgZOBLA4gxXQRQ/JOD4NjCsYmA4v4DZACgmzcBQbHHAn4EbyOZSDQ1ReC8cyXAOyGEDejvBtJwv9gEDAwBMADQNYPFDtwAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\frac{1}{2 x}$$" ], "text/plain": [ " 1 \n", "───\n", "2⋅x" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "init_printing()\n", "fx = 1 / (2 * x)\n", "fx" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Вычислим интеграл (в sympy константа $C$ в неопределённых интегралах будет опускаться):" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAqBAMAAADi/wAlAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMt0Qq5nNdrvvIolEZlSFnHVmAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB4ElEQVQ4Ee1STWsTURQ9k5l8zDhJiwWRusgsEgqBSiqUZimC1IXgLKIiKqQ/QDPQQnaKGBC6EEu7VJxNoLgoWcRVFg4iQjeajR/LoSvBRRODYOOi3pfHm/ciGbp14YW595xzz/uY9x6A02WcFPrl+skm4OF/0z9yBD6/UYuVKy8LHqeTOR1ybivdMzuTHnwX/IEAVAsKJqjXKI0jpTyAphB5TfYEz7oCAX+ZTNnZllAx+aS+l517EpJpuXEHeNf5ckDqbfpWNpa6IdBRTVoJGU8b4oVNKhvupleTDvBZNSXa0AaGg0tMPA9k/fTIoP0f4JhFn9Qm8iHwW5ieAxoyNWogzxKPJg4D4Jc9xCITyATMeCzvs8SDz/RTr3ZoBeA+Sx99vcyWi6IJ04U9yAVceQJUgms4Rexr5KE9aVtIte21eRo8/u/DuVv4QPBmZDp7tIlW9ypQP/7BdvKWHVvubkiwBLRuPIqcBDKhvrdANTErVMuBdRFvAsGpfqOPbUJeK121UYb5TDFdoBmeMr4pxF3AHMIYCU5V7zZej1eqCPExQCdsDARXq9XjLOuPa6KvNmNw3otpqHJRJTE46cY0VPmTSmJwro1XMS0pnwPWJZuOrOL1qjO9JdUUvd6apFPRHxz/blDUaEi/AAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\frac{1}{2} \\log{\\left (x \\right )}$$" ], "text/plain": [ "log(x)\n", "──────\n", " 2 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(fx, x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Или что-то более сложное:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$f(x) = \\dfrac{1}{1+x^2}$" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAAVBAMAAAAJGoXuAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZnaJEFTvIpnNRKsy3btb54ZLAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABWUlEQVQoFXWRMUjDQBSG/8SmrTba4uZSgiIIHQzoIh0suohIKTqKdBGUuhxODiJRQXBrBcFJXBQcJFJxclDBVdtFdBbRRQQdrEvBd7k8K605ON6X//9CLgkQtIQqIkE95XpOlR1WsDTDVT9DGwPPUJGpPePTCic8owkmzfFpgBOeYQZgXqH53YgUHTeCEtDdN4zZ+kXOg9vF5ZQl603aY6mpIXq7NIwFbAOP8GHJMmvSoZvh6OVoFeiRlSt8h+AF+JDOPaAJvRajo8/R5eSo5yh4Bz6lUwBMdBUlVoCJ87xyPPjjAHFLOkcwCqhIx1bAzq5sXRHKyGeFHbirYg+2AnaegOzBJeT3TyLuYPBajMBWsO+fJw3kb7ZwSM4GzPL0+A5iZ8KDu6+3ZP2UihM6aK+xniN8oP3v6rziOFJlap6/fxKNv9vs4JWTNYbWmeXomaF1RhIq0wR+APIXV5Tzo0tfAAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\operatorname{atan}{\\left (x \\right )}$$" ], "text/plain": [ "atan(x)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(1 / (1 + x ** 2), x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$f(x) = \\sin(x) + \\cos(x) \\cdot e^x$" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [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oo294TnsCiU02gKO4x5mn79UqMNDEGWc/8PLzi+hhNhpbllaGArKKALzqjiUg+fftYCf4GLgkvH4FUsjSZaTt2cuOWu1CrUZvFOCiqyqbqwB1fMrKUqRuLND8DzBYODDrsKRkGztbY6POpICtAmpgluIjdttqWXMC2rjIKiZ4mfY9kFh2An4dEgt0eDLov0xGM+t+af3g0AlkW5ZRhgKyCjP8Cm5Ylk/wE0Mec2L5Dp8iiR1oEJZYwTXtT9HGMn8PduZj79dJ0thSVh0KyErMMF3cefkEs8D6yunWh/cY30D7HkhstojYB31LdF8hM9O6D9A4R5fixSLYLQWNLXcPTnQfBEEmm+EzeZxgN8GPvvtgGPj26QfxCIHbuTk1qw6Jpa/Q/uWhhUSDvpKKraetHuelOr7vX0TWIVpjq3pShh61giCrkuEUcH2bfmh6pHLowvFD/3107MpcO4U99F1e6t/VoOUTPOU7gZFNVOnrv/j1u4QkHXrZMH4L0uPDlcStpa3MRmPL0nzUEXN4KIMsLcO5f8/u4+WaKVkXyXSVR74TmNnHBYbX3MgXaGx96sWfa3nfUg5lOHlgv6U8Uxa8+zC2V2To+hpZ73nOe8bzOGhsfWrtyibfSglluE+pCCROiNWkCHyzmW192lllesZX74VWW/ER9sqDkQSbu2hh9LjQHsdF4JvNLD0+tEdW/wZbbTudQILNXbRaSE+1O8k47TnwamFf54VHA4C7sNp2OoEE902P1l3jkEEU1rLVfOl+i6pI2Xyafu/XNqKwlh2P40jFImukDzW5blNRWPMe2apZ0ym7HV22u1wU1rxD3P0DxVzjKvQIvHutN0IU1m1ACbJNxMP8E+o34LRi0mUiCmveIldF35JZVpQC8IeS7DIRhTVvQX/F5WbMsqIcRu+ikuwyEYU1b5Eu4+68WVaU9H2nwpQH+ChswCi4OPzAvcGEefU/tJ+1kUNlqeQAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\frac{e^{x}}{5} \\sin^{2}{\\left (x \\right )} + \\frac{e^{x}}{5} \\sin{\\left (x \\right )} \\cos{\\left (x \\right )} - \\frac{e^{x}}{5} \\cos^{2}{\\left (x \\right )}$$" ], "text/plain": [ " x 2 x x 2 \n", "ℯ ⋅sin (x) ℯ ⋅sin(x)⋅cos(x) ℯ ⋅cos (x)\n", "────────── + ──────────────── - ──────────\n", " 5 5 5 " ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(sin(x) * cos(x) * exp(x), x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "А теперь посчитаем определённый интеграл. Для этого достаточно дописать границы отрезка, на котором мы интегрируем, внутри функции integrate():" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHgAAAAVBAMAAAB/IDdlAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMquZdrvvRGZUIonaR28CAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACAUlEQVQ4EZWSPWgUQRTHf/eZva9kCWinpFQEPVmNlbqgjY23ksIikBxRN4UgZ2MV5ARBAgFjI6bysJMUOSzE8iCFYCEroggibBMsNSoIoqxvdoZNNhtC7sG8efPm/5t5O29haGtowkxD4gtaX+1s44onty1U2PCPuFA86qXz9RA+zt0Hc4jaPTC3mRbxgdE/kirsgMflWI9vPfL2FjCSwKs6eQVWJLJ2wDehZFNZptbeDX6tk09tZoMsvAyVTUr/4NEe8BTMuilYPXB1Qm5uUvoFx/aAZeu8DCk7N3+nR3VmeqEJ5TBGCt9hI45it/XNpmx56d+yI/CFgAe07Eq/B/l+rG514EUcxW4XuNCWHYHPQcudUtXK4w/EwaSMdcYdZafAwNccZ8VxTscKX3nLK/6FsdDAlZ5KltviWirSlr1Z98Ly6tLuse6aXVAVa/ilYp5rUPks/JZGkNzcPjgzrWT5gbh6yBdVdmIZuBgyYsff/BjW3DdaaXVkvgy34VXCZm9+7/vSavVgl1yO8+ziOyUe9eT3nPRvNGE+gUuLP6+ahWnViSj6Ie16+CRo3NqQXzmKzoigKpSE0QScNfrUlPQ5lV3i0LoqWRqjrSHHZG01m5I36kJNBvFDK0W5r/y+LCc3WgORWoHRf9oXp0WHv969rqJcV6+5Z+ahps9aXQv4D91/eBtLz+GiAAAAAElFTkSuQmCC\n", "text/latex": [ "$$-1 + 2 \\log{\\left (2 \\right )}$$" ], "text/plain": [ "-1 + 2⋅log(2)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(log(x), (x, 1, 2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Обратите внимание:** в таком случае все аргументы функции вводятся в круглых скобках – они должны быть оформлены в кортеж (*tuple*). Пример кортежа:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "t = (2, 5, 10) \n", "t" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Иначе ничего не получится:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "Invalid limits given: (x, 1, 2)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mintegrate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlog\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py\u001b[0m in \u001b[0;36mintegrate\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 1289\u001b[0m \u001b[0mrisch\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'risch'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1290\u001b[0m \u001b[0mmanual\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'manual'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1291\u001b[0;31m \u001b[0mintegral\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mIntegral\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1292\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1293\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mintegral\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mIntegral\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py\u001b[0m in \u001b[0;36m__new__\u001b[0;34m(cls, function, *symbols, **assumptions)\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfunction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_eval_Integral\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0massumptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 75\u001b[0;31m \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAddWithLimits\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__new__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunction\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0massumptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 76\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.6/site-packages/sympy/concrete/expr_with_limits.py\u001b[0m in \u001b[0;36m__new__\u001b[0;34m(cls, function, *symbols, **assumptions)\u001b[0m\n\u001b[1;32m 366\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 367\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msymbols\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 368\u001b[0;31m \u001b[0mlimits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0morientation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_limits\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 369\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0;31m# symbol not provided -- we can still try to compute a general form\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.6/site-packages/sympy/concrete/expr_with_limits.py\u001b[0m in \u001b[0;36m_process_limits\u001b[0;34m(*symbols)\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;32mcontinue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 69\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Invalid limits given: %s'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 70\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 71\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mlimits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0morientation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mValueError\u001b[0m: Invalid limits given: (x, 1, 2)" ] } ], "source": [ "integrate(log(x), x, 1, 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "А теперь рассмотрим какой-нибудь несобственный интеграл, например, интеграл, где оба предела интегрирования стремятся к $\\pm \\infty$:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAJBAMAAAD0ltBnAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdu+ZiURUMmYiu6sQ3c2sJJ3AAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAPklEQVQIHWNgEPr///9nBhbXlArxAoYyBknGAgYgWMB9AEiyb+AFcZgT+EHU+QP8AUBKjoHJAUgtY+B2YAAA88kMj3opkRQAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\pi$$" ], "text/plain": [ "π" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(1 / (1 + x ** 2), (x, -oo, oo))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Примечание:** символ для бесконечности немного нетривиальный – проще всего его просто скопировать из какой-нибудь документации sympy (если под рукой нет готового файла)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Интересный факт:** вместо готового значения можно вывести само выражение для интегрирования:" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHwAAABGBAMAAAD80e1GAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZnZEEDKrVM273Zkiie+CdhlgAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACkElEQVRYCWNggAJGZQYGR1UYj1SaJb2ihT2VWYBUfVD1TAwMs6QZGGrI1M7IwMDxhYHBnXztbCsYGELJ1M4ewLDZawrLBjK1M8juDmC51eZArvaRri9XgZIQYFP+iEV7lAMWQWxC8a6PMYRZsvuJ1Z6BoRkkoE+s9k8UaWf+TJF2bmCOwwKIdTzXAyyaife7/wSKtNcrUKR9vwFF2tc7UKKd5R9W3cQmG/afFGnn/YtVe+b7ZQpYJdAEObAnOjRVUC5rH3qhyo890WHXzsBfgCYR/wBNAC/X3gFNWh57okNTBePegjFgdP4FGIsYuhtd0Xp036ArQPB59qp+Z2BRSom9jhD7fwDBJsCyO8D5hYGbQU1hF1wh6384kxCD5SEDdwODDIP+gUS4UsYfcCb/fzwAqApYrnBdYAhgmAHXART7jcTBz+SbwOBvAFSCXDZyYCvjsRvjf4FBHijD/IfBBa6A/yucSYjhX8Awg/3IZLYPDIi4Pv8BXZfvtRR0IQifQ4FxNS/7V+8HzIi4rm9AV7uBAREvKHIsSVePqbJsUqgWRwjfRzgEKviZ4XwAQh7EYl2CykfizTdA4oCZIuja3XbgzpTvHdC1MzBA8wW8sciEUzvLL0zdMLeyK0DlcGtn/oap/aQDRIwI7UzIqQaSmXgSWA+A9ROhne0PxCYwCclMJ0OjHYjVzvcArBJCQDLT+//QTEiE7f4JSNqRMxP3qlXrXq1aBZbGHXT2AkjaUTMTAxG26x9A1o6SmYjRjpz1WVAzEzHakbM+WmYiQjszcnJEy0xw7WzzfiUhexHG5m1gS4CxsdDwoMMiBxLinBDngEMKJAzPMjjUsGzKwSEzKjzYQ2Bo9r8jZwLBgRHZ/wYAtYK+nhMEc7cAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\int_{-\\infty}^{\\infty} \\frac{1}{x^{2} + 1}\\, dx$$" ], "text/plain": [ "∞ \n", "⌠ \n", "⎮ 1 \n", "⎮ ────── dx\n", "⎮ 2 \n", "⎮ x + 1 \n", "⌡ \n", "-∞ " ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Integral(1 / (1 + x ** 2), (x, -oo, oo)) # Integral vs integrate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Про особенности вычисления интегралов в sympy можно почитать [здесь](https://docs.sympy.org/latest/modules/integrals/integrals.html), раздел *API Reference*." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Пределы в sympy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Посчитаем предел функции $f(x) = e^{-x}$ при $x \\to \\infty$:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAdBAMAAAD2nkd3AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMs3vq927ImZEmRB2iVQin4g+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABe0lEQVQ4EdXTv0sCYRgH8O9r6p3c6V1b2wm2ReUQztdSDtFQ/4AQGVHgha2B0GQQuDRGbUdNBhXREDZFcoIEBZWDtLTWEAQ19HivqZ1v2trLcT++z+d9n/cODug/1PKG3V8BV/7UWMOxmIls7vcZuWBJd6sBE3v7AsfSNJYAjTMETSgC1ooMWO49uR5Dit+g+genJHcrxaaTYiabt51kyFlurqzUyrzY0Yn60qsMzMDIY7OZ7+iMN/vpiAbj0FIwLLcgvUMtdBD3toHoSEGrwtB59Fm59zIXcVf6dprZpSB0XZujee2+rfUC5OreJfnmfLS/lpOjOLc8jmUSawuJo0xiKDMRHh/l1YpT8rD/8ljovVHHfuAf4JqcTKezS9EE1Zry1d3CKaDMPo1EJkM5AZSxynjMpqECi1vAs8ABr8Bd44dJv1ky4PsALkSOvUg8Vqsg558DBgUuG46GebwORHQcnKwo+wJ3nK898timy/ahrtwOFwWuHfWsfgEfy1WGtnHaFAAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\lim_{x \\to \\infty} e^{- x}$$" ], "text/plain": [ " -x\n", "lim ℯ \n", "x─→∞ " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Limit(exp(-x), x, oo) # пока само выражение" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOBAMAAADkjZCYAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAiXaZIs1UEN1mu6tEMu+iw/3TAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAV0lEQVQIHWNgYBQyYWBgCGOocGDgbGBgXMDAtYGB7TsDvwEDzzeGeiD5k8FfgIH3E5j8yFAvwMDzCSTL9o2BawED53cGzgcMzAEMDG0MdRcYGAqV9jIAAMSUErnbiJtLAAAAAElFTkSuQmCC\n", "text/latex": [ "$$0$$" ], "text/plain": [ "0" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "limit(exp(-x), x, oo) # результат" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "А что, если предел равен бесконечности? Проверим:" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAABMAAAAKBAMAAACkp3isAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnaZZhC7ie9EVM0iq905P93KAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAb0lEQVQIHWNgEDJhYGAIMQlgYGBJquhk4NoZWMjAcJiBdf+EtQwM7AwMBQwMEb82MDAwTmBQYGDg/D8BqNwBxGSovwAkFMDMbV8YGHgWMCxkYOBdsH8CA3sAA3MAaxJD3JcYkOm1uQIMDNq/FzAAAO/uGCbPqITdAAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\infty$$" ], "text/plain": [ "∞" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "limit(exp(-x), x, -oo) # и правда" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "А если предела не существует совсем (даже не-конечного)?" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAVBAMAAAAOWFv7AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIruJVN2ZMhDNdmZEq+/d7cTSAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA6ElEQVQoFWNgYBBgwA4KQMKMCkACG1AHCTI7IKRKG6Bs9ggGBjcQmxUqwMDAcW1+A4TTm/kDKgFWAlWxHirLwAWUBRsKNh6bLKMC0LgJUBkQhaKXYSIDA9cGnLLOyI7C0At071kkrWgmsx1gyAFaPTUUBIBhg2ov+wWG1bj1shgwdOKW5RRgYBJAkgaZDERAnwBDg0GIgQGoHQGAshw/QVywrAmQEYCQvPQ+dgFDaAMDA6/e11sQGZAKZMDSAOWxJAAZQNNRADOMB3YRZwOMC6G7YFywb7gXwLgQegOMCwkJBRgXjQaKAwD3mDYzMQtRhAAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\langle -1, 1\\rangle$$" ], "text/plain": [ "<-1, 1>" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "limit(sin(1/x), x, 0) # странный ответ, попробуйте понять, почему" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sympy также умеет вычислять односторонние пределы:" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGUAAAAsBAMAAACOBWtYAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMs3vq927ImZEmRB2iVQin4g+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB1UlEQVRIDe1VPUvDUBQ9adPGNq3VQXSRCp2lHaSrGURFHRR1caoKQlFoREFwEhykDtJ/oIhSrA5RxEGXDC5iwU4Ofs9O7SAdFOp7eW2SFiFJB6dewr33nHMP773wQgBb0aXYGjMNiWNRxx7goeVpvQNyi5q4B8ODM6rp/tGWi0hY22ograBHwv6B1VCD7pUgNlCWkHgcR3MeISJx09n8qC+ftLkiWYe8BvcEwmls2/cQmzeGUAJh2Z6JGsiTQKiAcEfVE6r8HUWmGx7V8Fgs95+eBFzkPLb3xqXiq4vx81S8JzUQjPZbHMSpvHk479QiSHjPODTxCtwxhx73N/iyQw8/Cb7U4BFfhxSDEvPjvW8GZJ2nenV03g//pA7gx616bEDWhVUzkwFCGcG09A4e5FHzBO3naMpnn2RacQe0KUJJyOVyJxrRgQWtXszSmNJ6/wEpAXnY9aHBK5qDpr0BP5pgTrsUtGGFYyQ3QmrdD9pXxg3Tarm9gA3akxM8LtH4kiEs11RATPJFFAxMu17gnhSuKDA+QPR1dDNAcnvpOub70CFthLncEdn8WrAvyPh1ws13nupD4pn6uacjrXGRr70PuEy/PDMhC7grlWL9lAVSLHRd/gW84I21z62sYgAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\lim_{x \\to 2^-} \\frac{1}{x - 2}$$" ], "text/plain": [ " 1 \n", " lim ─────\n", "x─→2⁻x - 2" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Limit(1 / (x - 2), x, 2, '-') # левосторонний предел" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACMAAAAKBAMAAADMVPqUAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnaZZruJ70RUIqsKEj5BAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAgElEQVQIHWNggAHXdCBLPF0AxmdgYG+dtZqBR1tkCkLoGgOj/oZzDAycCKEJDAxSfxQYGFg2MAgZg4AJQwADA/f/DUAlBXBlQCGG+Q+ABIgBASCWxncGBt4DUAEGhiMMDHwH9DcwcArAhdgEGFsZhL/LglwHA/P6HBgYgj4dYAAAf14ZMFtvYvoAAAAASUVORK5CYII=\n", "text/latex": [ "$$-\\infty$$" ], "text/plain": [ "-∞" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "limit(1 / (x - 2), x, 2, '-') # вычисляем" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Limit(1 / (x - 2), x, 2, '+') # правосторонний предел" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "limit(1 / (x - 2), x, 2, '+') # вычисляем" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Немного про матрицы в sympy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Создадим матрицу M и посмотрим на неё:" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzBAMAAADFkV1eAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGYizbsyq4nvdlTi2OUeAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABLUlEQVQ4EWMQFBRkwAIYBQUFGPT/f8YixcDx/38Dgwo2GZAYK2G5ZPNOFN2cinB9bAsY9jsgSUqZf4TLcQkw8BxAkmPgRcjxfGTg+oZDjkuBgesnDjmgMNMH3HLzL+CWU0aWQnYLAwOzAW65YBQpFH18GxjSkGWR/Mcwm4HhIg45NmVjKwUccuz///8vQJLj6vm0lqg4QtKDYBIRtwjFSKzhpG+SAJLHGNiMKybAwpNxcT2KXBYD9xeYHAPDfRS5hQwMZ3DJnRdgWJ8Az0eo+hYxMKyfgEMO6C59XGYyMHD+xS3HZIBbzhhoLCz+UN3CwArUhkvuNQNbAg45zg0MvAI45JKMjYFehNq34rzWBaTArv///ztcDkkcwYS5EyGCYA2AnCquslW2AV/ZCgB1dWgeQXjgLwAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left[\\begin{matrix}2 & 1\\\\1 & 2\\end{matrix}\\right]$$" ], "text/plain": [ "⎡2 1⎤\n", "⎢ ⎥\n", "⎣1 2⎦" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M = Matrix([[2, 1], [1, 2]])\n", "M" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Найдём обратную матрицу:" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFsAAAAzBAMAAAAKv2mdAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGaJqyIyu+92zVRjo6itAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB/UlEQVRIDb2WP0sdQRTFz/q4ZjcK7jYWmkKDr9ZYp8hHSGojiEXSKCRNot2rFETwkYDkgaAphRRaWhkEeYUKwVoI5BMIapFqc2f2z8zecZb3RHKL3Zkzvz3cnWUPgyRJoCp49znWg3svwTwTSRJjOr3RQAONiXtJLe6cAE/TdA9TOTPyKvzrx/FHrZHBKe4LBwYn2MBX0h34UvOqTjMIv/ucle64r+NbDS/xcL/zog98KE2v/fja75e8SGYj/ahZeVw8uHyuql34W+4pl7f5EbX6H3sPT7tlj0Wv5r75dpUnZDbyycLwgVmWo084Y4kMHrUHf0nIzDtY5gkZHBh4bZbdUZMlsvDhK5cxysVPHpOFY0wpvgp+8ArZeFT3r2KX983Cx9vhHXwVHGGL38zCB2I69NHAJObiCh4tdVtQ6ePU6PuP2D5fYZ3s3nmu0sepGczmGgk8+4PFA7fY4tdURb3gb/rDgUVlzUW9uCOaVCwX9YRv8B7q6gkPP0StPvCNztfcXrpn6ZNZlddj9VfrItl7rntuD8Jl+ni8nY3M06eKW+KDmqm61cyke5Y+4gEjSjxLH4EbUeJZ+gjciBIHVPo4VYgkv6pOH4mXooPr9JF4KTq4Th+Jl6LA8/Sp4pbIeDM//mgmS58qnkeSOv482yuPP5rJ0kfghaiOP/8A0bCbxHEB3/EAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\left[\\begin{matrix}\\frac{2}{3} & - \\frac{1}{3}\\\\- \\frac{1}{3} & \\frac{2}{3}\\end{matrix}\\right]$$" ], "text/plain": [ "⎡2/3 -1/3⎤\n", "⎢ ⎥\n", "⎣-1/3 2/3 ⎦" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.inv()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Найдём её ранг:" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAkAAAAOBAMAAAAPuiubAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpnNuzKriUQQ7912ZlSugimNAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAT0lEQVQIHWNgVDIJYGAQY2D/wcCQycCwioFh/QSGfAGGbAaGfKAEA8N+EMH6B0RyK4BIJRDBqwAinzMwCjCwFjDwTGCQVlICarH///8zAwAXpw31OpgbMwAAAABJRU5ErkJggg==\n", "text/latex": [ "$$2$$" ], "text/plain": [ "2" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.rank() # в данном случае ожидаемо, что он равен 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Посчитаем собственные значения матрицы M:" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHwAAAAVBAMAAAB2y5cfAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEER2zVSJ3ZkiZjKru+/kt61jAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABZklEQVQ4EWNgYGBUYiALTJ0A1mYSSJZuBu6zAkCNrB9BureDmDDAXQhjIehpGZcQHAawCt4DQBG2AqD7T/gjaZdpAZuIpBqoooFhfQBcBKICpBOsnYHBHkk7AzOmduavDPIOcO0QFSRoZ3rEwE+BdqDF8QsI2l4BVoHF8QwMTFVgOSQVYMdzOICEIX5n/AJWgk07t81pkByyCuYHQIH5C4AELOggAYhNO9Dx4JBHUsH5lYFhTxFIN0w7mI0t5IESfEjxAbFgrisDYwvYPEIRx72BgRdoGQxAtKcoMDCA0w5B2+U/Ympn/Qk0DRx+mNoZYRZBaL4DmI5ne4CmHSlckdMYUBXXAki8I6mAWAy2/ez7GgOQNeBY5bn3/TADO1q20eiAZBmECiTtIK1oIBCNj8lFSvOYkgmYQmgiYO3gtIMmAeQygj2DKY4kAk6vjE+RRBBMLgQTF0tuAUhmxlFc8vjFtwH1AQDEAFyubqTglgAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left \\{ 1 : 1, \\quad 3 : 1\\right \\}$$" ], "text/plain": [ "{1: 1, 3: 1}" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.eigenvals() # два значения: 1 и 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "И собственные векторы (какие-нибудь):" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAAzBAMAAACQ1ekpAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGariSIy73a7VM3JC78mAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAG1ElEQVRoBcVaPW8dRRSdd+P3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ja7n8fzaLOKwbrxCFQc9tcs+/lj0ui5wlgy1KziG8sVFafcV16fJf7NAD2Br7y8qyX2Fo/v4jusD6Vf/LJobrU5dDKiZzETypiObiayXxbpjv9Ua46TAI1A+1de1xp9MfBpcbQ+2PiV153m2sZXXv8A2WoAFKF66bUAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\left [ \\left ( 1, \\quad 1, \\quad \\left [ \\left[\\begin{matrix}-1\\\\1\\end{matrix}\\right]\\right ]\\right ), \\quad \\left ( 3, \\quad 1, \\quad \\left [ \\left[\\begin{matrix}1\\\\1\\end{matrix}\\right]\\right ]\\right )\\right ]$$" ], "text/plain": [ "⎡⎛ ⎡⎡-1⎤⎤⎞ ⎛ ⎡⎡1⎤⎤⎞⎤\n", "⎢⎜1, 1, ⎢⎢ ⎥⎥⎟, ⎜3, 1, ⎢⎢ ⎥⎥⎟⎥\n", "⎣⎝ ⎣⎣1 ⎦⎦⎠ ⎝ ⎣⎣1⎦⎦⎠⎦" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.eigenvects() # два собственных вектора" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Приведём матрицу к диагональному виду:" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMcAAAAzBAMAAADRKAH6AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAq0Rmid0iMu92ELuZVM0av29pAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADjUlEQVRYCb2YvWsUURDA53LuXdwzyYmNouA2gt0FRBAtbos0YpHEoEUa8yekCWKVCEELEWOteM/SVbwTEYQUuVJQ4jWCWJg0NiJY+IXxY52Z996+t5u95MztZoq382bezi/zvm6yAEqCINBq6rOb3w0CkfbCJnvBA7gU/k4bG9lWwl+RbitOGLbtvtYrYdgCeC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\left ( \\left[\\begin{matrix}-1 & 1\\\\1 & 1\\end{matrix}\\right], \\quad \\left[\\begin{matrix}1 & 0\\\\0 & 3\\end{matrix}\\right]\\right )$$" ], "text/plain": [ "⎛⎡-1 1⎤ ⎡1 0⎤⎞\n", "⎜⎢ ⎥, ⎢ ⎥⎟\n", "⎝⎣1 1⎦ ⎣0 3⎦⎠" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.diagonalize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Почему результат включает две матрицы? Вторая матрица – это итоговая диагональная матрица, а первая – это матрица $P$ отсюда:\n", "\n", "$$\n", "M=PDP^{−1} \n", "$$\n", "\n", "**Примечание:** $M$ – это наша исходная матрица, $D$ – диагоналльная матрица." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Можем извлечь диагональную матрицу из полученного кортежа:" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzBAMAAADFkV1eAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGYyq812u++JIlSvzbOnAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXUlEQVQ4EeWUv0rEQBDGv9WsSLiLiVaicBaKlX/ARgThsLW4Q7CyMFgIVgqCgpVPoAcWYmU6weastLy0J1f4BuYNDhFBQYwbcScT2D2uFPyqyf7m253ZDIsgCGCQCAIfC+mrAcFN0wjTJpKtyT7Yjp9lkjoXT9onDs8LbDgRc5oB1wW2ATza2A3Q9SF/ayn6VFO1xMxExupmVv4E9hs9WGxmQvlqFh/UeV1LLbgFtm09bAHLtt4HEnFP7KQ120Au0b4MieXLLJJ9/D+WTuE/8ZXaq9SyCsqdlSrd5xlG1SCTxiC/NJNTKEVE1CQn4l0z9wDeC2PrVRAbWYSjNmHy3rSvopj6YFqra/YcY+iDEewdh5ypmWTyqM5KDKfgA1p6BlUtWSJpF2gmkD/z4kaQrAeR+jmTdxg8JRfwwPbEPCZCxjaR94fJqyOG4Cyxu+aAYvm3ZnfG9raOR73e1m/EUnoqLW8llgAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left[\\begin{matrix}1 & 0\\\\0 & 3\\end{matrix}\\right]$$" ], "text/plain": [ "⎡1 0⎤\n", "⎢ ⎥\n", "⎣0 3⎦" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.diagonalize()[1] # второй элемент – элемент с индексом 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Или используем множественное присваивание:" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzBAMAAADFkV1eAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGYyq812u++JIlSvzbOnAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXUlEQVQ4EeWUv0rEQBDGv9WsSLiLiVaicBaKlX/ARgThsLW4Q7CyMFgIVgqCgpVPoAcWYmU6weastLy0J1f4BuYNDhFBQYwbcScT2D2uFPyqyf7m253ZDIsgCGCQCAIfC+mrAcFN0wjTJpKtyT7Yjp9lkjoXT9onDs8LbDgRc5oB1wW2ATza2A3Q9SF/ayn6VFO1xMxExupmVv4E9hs9WGxmQvlqFh/UeV1LLbgFtm09bAHLtt4HEnFP7KQ120Au0b4MieXLLJJ9/D+WTuE/8ZXaq9SyCsqdlSrd5xlG1SCTxiC/NJNTKEVE1CQn4l0z9wDeC2PrVRAbWYSjNmHy3rSvopj6YFqra/YcY+iDEewdh5ypmWTyqM5KDKfgA1p6BlUtWSJpF2gmkD/z4kaQrAeR+jmTdxg8JRfwwPbEPCZCxjaR94fJqyOG4Cyxu+aAYvm3ZnfG9raOR73e1m/EUnoqLW8llgAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left[\\begin{matrix}1 & 0\\\\0 & 3\\end{matrix}\\right]$$" ], "text/plain": [ "⎡1 0⎤\n", "⎢ ⎥\n", "⎣0 3⎦" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P, D = M.diagonalize()\n", "D" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Можем разложить матрицу, выбрав определённый метод разложения. Например, выберем LU-разложение, то есть представим матрицу M в виде произведения нижней треугольной матрицы (*Lower*) и верхней треугольной матрицы (*Upper*): " ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOkAAAAzCAMAAABFTN+YAAAAM1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADxgEwMAAAAEHRSTlMAq0Rmid0iMu92ELuZVM2Tj3BL4AAAAAlwSFlzAAAOxAAADsQBlSsOGwAABXJJREFUaAXlWtsCoyoMhCredf3/rz3cQhJA1mj3pacPLVLJzECAEFUq+yz+k1W2L8VNxA2UvEWDsv74P81pP1vjvvKv1TVZy/rLGjmGGCJiL+tSsNBdqDJBcPH/Xyo6kdJHGCIIoDseuVTdx/9+TKnaDYgOv126pkpHk3cIa9X38zbEGlGHA8awbcc6MpvZBWUggkA7m8ayUsOZ8ICFWvR2nC2lx67UYqJUEY2IMTgO/XnpyhkDEQRRZ+K89FUGfFeppNT+MbeUBjfo4/wU0YgY2vfjNBFWeZEyEEEQQ/uE49URsNtKV+8Ve+wMEY2IMfm2+oQZQNhB8RtK1YFbyYRDen9Mw1b0Oa0P288TpdovDhpnDujD368o/aS+pOZuK11AaZgFT5QGQeZEYUWJUhNBMEtpUA1dne5673B6RxjP2RsV0aAYYIBRSxffUQpTbGTuQ1lQnAQeC0lp8PzHSg1OohzCXlMGIghma4nDocl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MhOWfRN72XmBPR4BjESq2YKIggqKUQX4eaAzdvxoIcQGnTSllEg2FUjNEqpCCCICY+ZBzVOEFwSeap9d3K+4XEBC2KaAiUEgoiCMJtCm/XxJo5hfmEhXsHbExdQNpWiiIaBKNiilZRCiIINKLZI3/7CBH8F1kM6ziOG85gbFwpiWggRsUSrWIURBDJyp7GEKrWeA4ynXtr2NVOPuyE/xu/rsHMn8I27rZ/IUb7PqQghgDD5VuvSq3hkCN/y1iJXzOWY4ghotIFX+/9D0QBKrjdprxDAAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\left ( \\left[\\begin{matrix}1 & 0\\\\\\frac{1}{2} & 1\\end{matrix}\\right], \\quad \\left[\\begin{matrix}2 & 1\\\\0 & \\frac{3}{2}\\end{matrix}\\right], \\quad \\left [ \\right ]\\right )$$" ], "text/plain": [ "⎛⎡ 1 0⎤ ⎡2 1 ⎤ ⎞\n", "⎜⎢ ⎥, ⎢ ⎥, []⎟\n", "⎝⎣1/2 1⎦ ⎣0 3/2⎦ ⎠" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.LUdecomposition()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Проверим, что всё работает корректно – перемножим матрицы из выдачи выше. Опять извлечём первые две матрицы из кортежа:" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [], "source": [ "L, U, N = M.LUdecomposition() # N - просто так, пустая матрица" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADgAAAAzBAMAAAAwb9buAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGYyq812u++JIlSvzbOnAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABOklEQVQ4EWMQFBRkwApAEvr/P2OVY1j//xeDCnYpkGgUEZJsiqj6eU7awnWKW3xElexjELoAN5YTVZJVgYFnAS5JrgIGPqByqIPQdPIbMLD8wyUpD5T8ikvy/gEGtp/4JP/gkpQ/wMCCUyfQQXw4HcS1gIEVp1dYNzAwN+Cyk0GPQToBJsm++lMlSuDKzCwD8omJMhRtcM5g1SnaAHciEgPiWraZCkhicCbUK3zUk0wSABqO3VjG4n7ckgwM86khyXvi8wS478AMZGNRZYA8YiX/A8EHFN3E6kTRBOYg6WQ8Uw7yNBJAkmRmYFZAkgEykST5HXi/oUhW7VcHehwS8KwCaJIQldBYYeBRQNGJKgmOP3R5qE7ehegSID5U8jpDLhZZiCTvsjRDrJKqwDKXGz1oQSoFBWfhLYwBDvNkUor/wBcAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\left[\\begin{matrix}1 & 0\\\\\\frac{1}{2} & 1\\end{matrix}\\right]$$" ], "text/plain": [ "⎡ 1 0⎤\n", "⎢ ⎥\n", "⎣1/2 1⎦" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADgAAAAzBAMAAAAwb9buAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEN2ZRGYizbsyq4nvdlTi2OUeAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABjElEQVQ4EdXUv0vDQBQH8G/tD9u0tI1rhbbULg5aFBSc/BMUlw4KBUG6SPsXaFcHUXQqHVoRRHEpLoIgdnWqTjpY/Bcs/kARjXlJk3uBXHT1lnt3n7zLu7sQqKoK10YwqT27Gna0d4y5E80Wf8fV2S1n/l7Szgy1cDXP1He4KVBJItZhCDwKjPWhvMlQyUD5kKE+P/Tkgc0bD8w5jBcE+AseuOQ0R2a8jTUHs32iAdzKMJSbnsvIcFjTtCrH4+44be0PV8azWPxPMtdXTqho92pP8SDHOs7lCOQFRi9naCDanfHVmO/cwEhJiB75tmloYDCDaI1GojV39djAcAvxvgD4rlFZsDBRQOCbIbJYTlqY1vGVY6N3RENj2UobkS+Og9jGTxmm2wjwzIT+TWnWsnpBcUdBfNlwDUG+FesN5iF04K9aM9SnLg6oMxATGKUTsVsBUxSbmOoZl2vjCyr0sIn27CBY9ELgjB5zz0Qk64FlOndJZqgVKUmxXN+n1CLyLj/jLh2tqt57/ox/AIawcEReUc7XAAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\left[\\begin{matrix}2 & 1\\\\0 & \\frac{3}{2}\\end{matrix}\\right]$$" ], "text/plain": [ "⎡2 1 ⎤\n", "⎢ ⎥\n", "⎣0 3/2⎦" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "U" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Перемножим и сравним:" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L * U == M # действительно" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Задания " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Задача 1\n", "\n", "Вычислите с помощью sympy пределы 1, 7, 10, 12, 13 [отсюда](http://tutorial.math.lamar.edu/Problems/CalcI/ComputingLimits.aspx) и сравните результаты с предложенными решениями. Всегда ли sympy корректно возвращает результат (особенно интересуют случаи, когда предел равен $\\pm\\infty$ или не существует).\n", "\n", "**Подсказка:** кусочно-заданную функцию можно определить с помощью функции Piecewise(). Пример:" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAA/BAMAAAALa9koAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIruZZhDNMomr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HMpzuk9mULTETFCZfOZR5F6mf8dun2FXQNvJP/OUwAD7AHQF+ZqGdtUE5SJ0lcTqKlkd/LBIye8PQzCK5yQx3hOmsJKbDbEQ1nU5Ybdguf6AqaFyR5fxUG26IVq1+dl3Ca7IezJHsLrofwqy03EbQxaMmEl9aYp0Q8GlTJ9rWXDFlpfyS8NGro4gdT1HL1+W9VjrpO2d/xSi70/geSvSOwY/fX/w6fWXvi2+oF5Ys9mE19Z9yWE5qplNFUpdjwjgrRP7vEdvghEdhvV0ARa/Pq2cg6eqcD1uJaUbmzQOi6CmFgmKrkcKoNaJCU5BZw7mAM7DScjDR9Bh4Pk6amZm8CzOYSmqmUmCTtcj0al14hV2YyOTxLPBIAwhoaIfPJWpsr37x0qdYCmsmVnfNHbXI9GpdXIEtcW1ax+AjUjoKJePYJeBgv3FRYKlsGamLeh0PYLPKzSyRgqwycAK+Yl5EP2xY9adXDCSV/q2tHqQ5oJy1yMUD/HWqS4IhwEyeFOx6Tirj3zBKtQsUHMcFkFNLS7o6nqcEN46pQopSLAKYbgK29kWAfgVsgUU7NZmIKpz2IlpblCFrq6nHsRaJ4BPtid7pl/umYfIrlH9hwu3o3cfpHPYXE0/8ebEuxyuR/i52s/QDzUYzv9fMBb2WT9+NphH4z+L6w/Cf1j7zJ1W+7FtRSbOtBXWfpBSxLc71BF6Twqvh1ffv5QGWLQOshhiAAAAAElFTkSuQmCC\n", "text/latex": [ "$$\\begin{cases} 0 & \\text{for}\\: x > 1 \\vee x < -1 \\\\x^{2} & \\text{otherwise} \\end{cases}$$" ], "text/plain": [ "⎧0 for x > 1 ∨ x < -1\n", "⎪ \n", "⎨ 2 \n", "⎪x otherwise \n", "⎩ " ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Piecewise((0, x < -1),\n", " (0, x > 1),\n", " ( (x ** 2, True)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Задача 2\n", "\n", "Вычислите следующие неопределённые и определённые интегралы:\n", "\n", "* $\\int(\\sin\\pi x) dx$\n", "* $\\int\\frac{x^2}{\\sqrt{1-x}} dx$\n", "* $\\int\\limits_1^2\\tan(x^2) dx$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Задача 3\n", "\n", "1. Найдите собственные значения матрицы A в общем виде (считая, что a и b – это какие-то числа):\n", "\n", "$$\n", "\\begin{pmatrix}\n", "a & 3 \\\\\n", "7 & b\n", "\\end{pmatrix}\n", "$$\n", "\n", "2. Извлеките полученные на предыдущем шаге собственные значения из словаря так, чтобы с ними можно было работать по отдельности (сохраните первое как lamda1, второе – как lamda2. Вычислите значения lamda1 и lamda2, считая, что $a=5$, $b = 7$.\n", "\n", "3. Найдите собственные вектора матрицы A в общем виде (считая, что a и b – это какие-то числа). Покажите, что эти вектора перпендикулярны друг другу. \n", "\n", "**Подсказка:** Для этого погуглите или посмотрите в документации sympy, как считать скалярное произведение векторов." ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }