{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Integração Numérica\n", "Existem diversos métodos comumente utilizados para encontrar soluções aproximadas para sistemas de EDOs. Neste documento introduziremos os mais usados assim com exemplos do seu uso no Sage.\n", "## Método de Euler \n", "\n", "No método de Euler aproximamos a EDO de primeira ordem por uma série de pontos no tempo a intervalos regulares de tamanho $h$ definido pelo usuário. Logo, $t_n=t_0 + n h$. Assumindo um EDO da forma $\\frac{dy}{dt}=f(t,y(t))$, a solução aproximada pelo método de Euler é $$y_{n+1} = y_n + hf(t_n,y_n)$$.\n", "\n", "Abaixo temos um exemplo interativo para um sistema relativamente simples: $$\\frac{dx}{dt} = sin(x)$$\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "%display typeset" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "520c2fbbf1cb48d6a301429e298b846b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function with 7 widgets\n", " y_exact_in: TransformText(valu…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def tab_list(y, headers = None):\n", " '''\n", " Converte uma lista em uma tabela html\n", " '''\n", " s = ''\n", " if headers:\n", " for q in headers:\n", " s = s + ''\n", " for x in y:\n", " s = s + ''\n", " for q in x:\n", " s = s + ''\n", " s = s + ''\n", " s = s + '
' + str(q) + '
' + str(q) + '
'\n", " return s\n", "\n", "var('x y')\n", "@interact\n", "def euler_method(y_exact_in = input_box('-cos(x)+1.0', type = str, label = 'Solução Exata = '), y_prime_in = input_box('sin(x)', type = str, label = \"y' = \"), start = input_box(0.0, label = 'Val. inicial de x: '), stop = input_box(6.0, label = 'Valor de parada de x: '), startval = input_box(0.0, label = 'Valor inicial de y: '), nsteps = slider([2^m for m in range(0,10)], default = 10, label = 'Número de passos: '), show_steps = slider([2^m for m in range(0,10)], default = 8, label = 'Numero de passos mostrados na tabela: ')):\n", " y_exact = lambda x: eval(y_exact_in)\n", " y_prime = lambda x,y: eval(y_prime_in)\n", " stepsize = float((stop-start)/nsteps)\n", " steps_shown = min(nsteps,show_steps)\n", " sol = [startval]\n", " xvals = [start]\n", " for step in range(nsteps):\n", " sol.append(sol[-1] + stepsize*y_prime(xvals[-1],sol[-1]))\n", " xvals.append(xvals[-1] + stepsize)\n", " sol_max = max(sol + [find_local_maximum(y_exact,start,stop)[0]])\n", " sol_min = min(sol + [find_local_minimum(y_exact,start,stop)[0]])\n", " show(plot(y_exact(x),start,stop,rgbcolor=(1,0,0))+line([[xvals[index],sol[index]] for index in range(len(sol))]),xmin=start,xmax = stop, ymax = sol_max, ymin = sol_min)\n", " if nsteps < steps_shown:\n", " table_range = range(len(sol))\n", " else:\n", " table_range = list(range(0,floor(steps_shown/2))) + list(range(len(sol)-floor(steps_shown/2),len(sol)))\n", " html(tab_list([[i,xvals[i],sol[i]] for i in table_range], headers = ['step','x','y']))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Campos Vetoriais e o Método de Euler" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1366df4241ac47b4ba6cfa64aa064ce6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function with 10 widgets\n", " f: EvalText(value='y', description='f', …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x,y = var('x,y')\n", "from sage.ext.fast_eval import fast_float\n", "@interact\n", "def _(f = input_box(default=y), g=input_box(default=-x*y+x^3-x),\n", " xmin=input_box(default=-1), xmax=input_box(default=1),\n", " ymin=input_box(default=-1), ymax=input_box(default=1),\n", " x_ini=input_box(default=0.5), y_ini=input_box(default=0.5),\n", " tam_passo=(0.01,(0.001, 0.2, .001)), passos=(600,(0, 1400)) ):\n", " ff = fast_float(f, 'x', 'y')\n", " gg = fast_float(g, 'x', 'y')\n", " passos = int(passos)\n", " \n", " points = [ (x_ini, y_ini) ]\n", " for i in range(passos):\n", " xx, yy = points[-1]\n", " try:\n", " points.append( (xx + tam_passo * ff(xx,yy), yy + tam_passo * gg(xx,yy)) )\n", " except (ValueError, ArithmeticError, TypeError):\n", " break\n", " equilibria = solve([f,g], [x,y])\n", " xnull = plot(solve(f,y)[0].rhs(),(x,xmin,xmax), color='red', legend_label=\"Nuliclina de X\")\n", " ynull = plot(solve(g,y)[0].rhs(),(x,xmin,xmax), color='green', legend_label=\"Nuliclina de Y\")\n", " starting_point = point(points[0], pointsize=50)\n", " solution = line(points)\n", " vector_field = plot_vector_field( (f,g), (x,xmin,xmax), (y,ymin,ymax) )\n", "\n", " result = vector_field + starting_point + solution +xnull+ ynull\n", "\n", " pretty_print(html(r\"$\\displaystyle\\frac{dx}{dt} = %s$
$\\displaystyle\\frac{dy}{dt} = %s$\" % (latex(f),latex(g))))\n", " result.show(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Campo Vetorial com Runge-Kutta Fehlberg" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "52e94b8dd4e2466ba28717cb24fbbbf4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function with 12 widgets\n", " fin: EvalText(value='-x*y^3 - 1/12*(4*y^…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "var('x y')\n", "@interact\n", "def _(fin = input_box(default=y+exp(x/10)-1/3*((x-1/2)^2+y^3)*x-x*y^3), gin=input_box(default=x^3-x+1/100*exp(y*x^2+x*y^2)-0.7*x),\n", " xmin=input_box(default=-1), xmax=input_box(default=1.8),\n", " ymin=input_box(default=-1.3), ymax=input_box(default=1.5),\n", " x_start=(-1,(-2,2)), y_start=(0,(-2,2)), error=(0.5,(0,1)),\n", " t_length=(23,(0, 100)) , num_of_points = (1500,(5,2000)),\n", " algorithm = selector([\n", " (\"rkf45\" , \"runga-kutta-felhberg (4,5)\"),\n", " (\"rk2\" , \"embedded runga-kutta (2,3)\"),\n", " (\"rk4\" , \"4th order classical runga-kutta\"),\n", " (\"rk8pd\" , 'runga-kutta prince-dormand (8,9)'),\n", " (\"rk2imp\" , \"implicit 2nd order runga-kutta at gaussian points\"),\n", " (\"rk4imp\" , \"implicit 4th order runga-kutta at gaussian points\"),\n", " (\"bsimp\" , \"implicit burlisch-stoer (requires jacobian)\"),\n", " (\"gear1\" , \"M=1 implicit gear\"),\n", " (\"gear2\" , \"M=2 implicit gear\")\n", " ])):\n", " f(x,y)=fin\n", " g(x,y)=gin\n", "\n", " ff = f._fast_float_(*f.args())\n", " gg = g._fast_float_(*g.args())\n", "\n", " #solve\n", " path = []\n", " err = error\n", " xerr = 0\n", " for yerr in [-err, 0, +err]:\n", " T=ode_solver()\n", " T.algorithm=algorithm\n", " T.function = lambda t, yp: [ff(yp[0],yp[1]), gg(yp[0],yp[1])]\n", " T.jacobian = jacobian([f,g],[x,y])\n", " T.ode_solve(y_0=[x_start + xerr, y_start + yerr],t_span=[0,t_length],num_points=num_of_points)\n", " path.append(line([p[1] for p in T.solution]))\n", "\n", " #plot\n", " vector_field = plot_vector_field( (f,g), (x,xmin,xmax), (y,ymin,ymax) )\n", " starting_point = point([x_start, y_start], pointsize=50)\n", " xnull = plot(solve(f,y)[0].rhs(),(x,xmin,xmax), color='red', legend_label=\"Nuliclina de X\")\n", " ynull = plot(solve(g,y)[0].rhs(),(x,xmin, xmax), color='green', legend_label=\"Nuliclina de Y\")\n", " show(vector_field + starting_point + sum(path)+xnull, aspect_ratio=1, figsize=[8,9])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}y = -\\frac{4^{\\frac{2}{3}} {\\left(x {\\left(i \\, \\sqrt{3} + 1\\right)} \\left(-\\frac{4 \\, x^{3} - 4 \\, x^{2} + x - \\sqrt{\\frac{16 \\, x^{7} - 32 \\, x^{6} + 24 \\, x^{5} - 8 \\, x^{4} + x^{3} + 144 \\, x e^{\\left(\\frac{1}{5} \\, x\\right)} - 24 \\, {\\left(4 \\, x^{4} - 4 \\, x^{3} + x^{2}\\right)} e^{\\left(\\frac{1}{10} \\, x\\right)} - 16}{x}} - 12 \\, e^{\\left(\\frac{1}{10} \\, x\\right)}}{x}\\right)^{\\frac{2}{3}} - i \\cdot 4^{\\frac{2}{3}} \\sqrt{3} + 4^{\\frac{2}{3}}\\right)}}{16 \\, x \\left(-\\frac{4 \\, x^{3} - 4 \\, x^{2} + x - \\sqrt{\\frac{16 \\, x^{7} - 32 \\, x^{6} + 24 \\, x^{5} - 8 \\, x^{4} + x^{3} + 144 \\, x e^{\\left(\\frac{1}{5} \\, x\\right)} - 24 \\, {\\left(4 \\, x^{4} - 4 \\, x^{3} + x^{2}\\right)} e^{\\left(\\frac{1}{10} \\, x\\right)} - 16}{x}} - 12 \\, e^{\\left(\\frac{1}{10} \\, x\\right)}}{x}\\right)^{\\frac{1}{3}}}$$" ], "text/plain": [ "y == -1/16*4^(2/3)*(x*(I*sqrt(3) + 1)*(-(4*x^3 - 4*x^2 + x - sqrt((16*x^7 - 32*x^6 + 24*x^5 - 8*x^4 + x^3 + 144*x*e^(1/5*x) - 24*(4*x^4 - 4*x^3 + x^2)*e^(1/10*x) - 16)/x) - 12*e^(1/10*x))/x)^(2/3) - I*4^(2/3)*sqrt(3) + 4^(2/3))/(x*(-(4*x^3 - 4*x^2 + x - sqrt((16*x^7 - 32*x^6 + 24*x^5 - 8*x^4 + x^3 + 144*x*e^(1/5*x) - 24*(4*x^4 - 4*x^3 + x^2)*e^(1/10*x) - 16)/x) - 12*e^(1/10*x))/x)^(1/3))" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var('x y z')\n", "\n", "sol = solve(-x*y^3 - 1/12*(4*y^3 + (2*x - 1)^2)*x + y + e^(1/10*x), y)\n", "sol[0].simplify_full()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)\n", "See http://trac.sagemath.org/5930 for details.\n", " complex_plot(sol[Integer(0)].subs(x=z), (x,-Integer(1), Integer(1)), (y,-Integer(1),Integer(1)))\n" ] }, { "ename": "TypeError", "evalue": "Cannot evaluate symbolic expression to a numeric value.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\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[0mcomplex_plot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msol\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mInteger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mz\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mInteger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mInteger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mInteger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mInteger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/misc/lazy_import.pyx\u001b[0m in \u001b[0;36msage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:4032)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 358\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 359\u001b[0m \"\"\"\n\u001b[0;32m--> 360\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_object\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\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[0mkwds\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 361\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 362\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__repr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/misc/decorators.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 489\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'__original_opts'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 490\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 491\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\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[0moptions\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 492\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 493\u001b[0m \u001b[0;31m#Add the options specified by @options to the signature of the wrapped\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/plot/complex_plot.pyx\u001b[0m in \u001b[0;36msage.plot.complex_plot.complex_plot (build/cythonized/sage/plot/complex_plot.c:6071)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 402\u001b[0m \u001b[0mg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mGraphics\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 403\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_set_extra_kwds\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mGraphics\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_extract_kwds_for_show\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mignore\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'xmin'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'xmax'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 404\u001b[0;31m g.add_primitive(ComplexPlot(complex_to_rgb(z_values),\n\u001b[0m\u001b[1;32m 405\u001b[0m x_range[:2], y_range[:2], options))\n\u001b[1;32m 406\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/plot/complex_plot.pyx\u001b[0m in \u001b[0;36msage.plot.complex_plot.complex_to_rgb (build/cythonized/sage/plot/complex_plot.c:3994)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0mz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m<\u001b[0m\u001b[0mComplexDoubleElement\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0mzz\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 114\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 115\u001b[0;31m \u001b[0mz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCDF\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzz\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 116\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_complex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdat\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0mmag\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mhypot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/rings/complex_double.pyx\u001b[0m in \u001b[0;36msage.rings.complex_double.ComplexDoubleField_class.__call__ (build/cythonized/sage/rings/complex_double.c:5419)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 334\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mim\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 335\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mim\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 336\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mParent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__call__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\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 337\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_element_constructor_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/structure/parent.pyx\u001b[0m in \u001b[0;36msage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9335)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 896\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmor\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 897\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mno_extra_args\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 898\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\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 899\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 900\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_with_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/structure/coerce_maps.pyx\u001b[0m in \u001b[0;36msage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4622)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_element_constructor\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_element_constructor\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 161\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 162\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0mcpdef\u001b[0m \u001b[0mElement\u001b[0m \u001b[0m_call_with_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/structure/coerce_maps.pyx\u001b[0m in \u001b[0;36msage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4514)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[0mcdef\u001b[0m \u001b[0mParent\u001b[0m \u001b[0mC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_codomain\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 155\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 156\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_element_constructor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\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 157\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mprint_warnings\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/rings/complex_double.pyx\u001b[0m in \u001b[0;36msage.rings.complex_double.ComplexDoubleField_class._element_constructor_ (build/cythonized/sage/rings/complex_double.c:5977)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 366\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 367\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'_complex_double_'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 368\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_complex_double_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\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 369\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mComplexDoubleElement\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx\u001b[0m in \u001b[0;36msage.symbolic.expression.Expression._complex_double_ (build/cythonized/sage/symbolic/expression.cpp:11835)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1663\u001b[0m \u001b[0;36m0.5000000000000001\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m0.8660254037844386\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1664\u001b[0m \"\"\"\n\u001b[0;32m-> 1665\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_eval_self\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mR\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 1666\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1667\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__float__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Downloads/SageMath/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx\u001b[0m in \u001b[0;36msage.symbolic.expression.Expression._eval_self (build/cythonized/sage/symbolic/expression.cpp:10179)\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1430\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mR\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mans\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1431\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1432\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Cannot evaluate symbolic expression to a numeric value.\"\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 1433\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1434\u001b[0m \u001b[0mcpdef\u001b[0m \u001b[0m_convert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mTypeError\u001b[0m: Cannot evaluate symbolic expression to a numeric value." ] } ], "source": [ "complex_plot(sol[0].subs(x=z), (x,-1, 1), (y,-1,1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.3", "language": "sage", "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.9.2" } }, "nbformat": 4, "nbformat_minor": 2 }