{ "cells": [ { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "import sympy as sm\n", "a, b, th, gama, x, t, y, z = sm.symbols(\"a, b, theta, gamma, x, t, y, z\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(a, b, theta, gamma, x, t, y, z)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a, b, th, gama, x, t, y, z\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "f" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = sm.Function('f')\n", "f" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\sin{\\left(f{\\left(t \\right)} \\right)} - \\frac{\\tan{\\left(\\frac{a}{b} \\right)}}{\\log{\\left(\\gamma \\right)}}$" ], "text/plain": [ "sin(f(t)) - tan(a/b)/log(gamma)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expr3 = sm.sin(f(t)) - sm.tan(a/b)/sm.log(gama)\n", "expr3" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{2 a \\left(\\tan^{2}{\\left(\\frac{a}{b} \\right)} + 1\\right) \\tan{\\left(\\frac{a}{b} \\right)}}{b^{3} \\log{\\left(\\gamma \\right)}} + \\frac{\\tan^{2}{\\left(\\frac{a}{b} \\right)} + 1}{b^{2} \\log{\\left(\\gamma \\right)}}$" ], "text/plain": [ "2*a*(tan(a/b)**2 + 1)*tan(a/b)/(b**3*log(gamma)) + (tan(a/b)**2 + 1)/(b**2*log(gamma))" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "part1 = sm.diff(expr3, a)\n", "part2 = sm.diff(part1, b)\n", "part2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Matrices & Linear Algebra" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 2],\n", "[3, 4]])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat1 = sm.Matrix([[1, 2],[3, 4]])\n", "mat1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Linear systems" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "lin_expr_1 = a * x +b**2*y + sm.sin(gama) *z" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x \\sin{\\left(f{\\left(t \\right)} \\right)} + z \\log{\\left(f{\\left(t \\right)} \\right)}$" ], "text/plain": [ "x*sin(f(t)) + z*log(f(t))" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lin_expr_2 = sm.sin(f(t)) *x + sm.log(f(t)) * z\n", "lin_expr_2" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a x + b^{2} y + z \\sin{\\left(\\gamma \\right)} = 0$" ], "text/plain": [ "Eq(a*x + b**2*y + z*sin(gamma), 0)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sm.Eq(lin_expr_1, 0)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x \\sin{\\left(f{\\left(t \\right)} \\right)} + z \\log{\\left(f{\\left(t \\right)} \\right)} = 0$" ], "text/plain": [ "Eq(x*sin(f(t)) + z*log(f(t)), 0)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sm.Eq(lin_expr_2, 0)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{x: -b**2*y*log(f(t))/(a*log(f(t)) - sin(gamma)*sin(f(t))),\n", " z: b**2*y*sin(f(t))/(a*log(f(t)) - sin(gamma)*sin(f(t)))}]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res = sm.solve([lin_expr_1, lin_expr_2], x, z, dict = True)\n", "res" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{x: -b**2*y*log(f(t))/(a*log(f(t)) - sin(gamma)*sin(f(t))),\n", " z: b**2*y*sin(f(t))/(a*log(f(t)) - sin(gamma)*sin(f(t)))}" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res_dict = res[0]\n", "res_dict" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x = - \\frac{b^{2} y \\log{\\left(f{\\left(t \\right)} \\right)}}{a \\log{\\left(f{\\left(t \\right)} \\right)} - \\sin{\\left(\\gamma \\right)} \\sin{\\left(f{\\left(t \\right)} \\right)}}$" ], "text/plain": [ "Eq(x, -b**2*y*log(f(t))/(a*log(f(t)) - sin(gamma)*sin(f(t))))" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sm.Eq(x, res_dict[x])" ] } ], "metadata": { "kernelspec": { "display_name": "blade", "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.10.16" } }, "nbformat": 4, "nbformat_minor": 2 }