Suppose you want to use a program such as Sympy or Maxima to find
the analytic solution of a complicated equation. After this you want
to make use of that solution for numerical evaluation of various
cases.
Is it safe to use the analytic results (without using a session) in the
following way, or is there a better way?
#+NAME: analytic-sol
#+BEGIN_SRC python :session none :results raw
from sympy import symbols, sqrt, python, solve
x, a = symbols("x, a")
y = solve( x**2 + 2*a*x + 1, x)
return python(y)
#+END_SRC
#+NAME: numeric-sol
#+BEGIN_SRC python :session none
from sympy import Symbol, sqrt, lambdify
import numpy as np
#+RESULTS: analytic-sol
a = Symbol('a')
e = [-a - sqrt(a**2 - 1), -a + sqrt(a**2 - 1)]
f = lambdify(a, e[1], "numpy")
t = np.r_[1:4]
return f(t)
#+END_SRC
#+RESULTS:
| -1 | -0.26794919 | -0.17157288 |
Regards,
Fede