From mboxrd@z Thu Jan 1 00:00:00 1970 From: Federico Beffa Subject: inclusion of #+RESULTS in a source block Date: Mon, 16 Jun 2014 16:38:50 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1133b4345360fd04fbf4fc36 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwY43-0007I6-2l for emacs-orgmode@gnu.org; Mon, 16 Jun 2014 10:39:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwY42-0004HK-63 for emacs-orgmode@gnu.org; Mon, 16 Jun 2014 10:39:15 -0400 Received: from mail-la0-x22f.google.com ([2a00:1450:4010:c03::22f]:43176) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwY41-0004F5-Tt for emacs-orgmode@gnu.org; Mon, 16 Jun 2014 10:39:14 -0400 Received: by mail-la0-f47.google.com with SMTP id s18so75861lam.34 for ; Mon, 16 Jun 2014 07:38:50 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --001a1133b4345360fd04fbf4fc36 Content-Type: text/plain; charset=UTF-8 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 --001a1133b4345360fd04fbf4fc36 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
=C2=A0 Suppose you want to use a program such as= Sympy or Maxima to find
=C2=A0 the analytic solution of a complicated e= quation. After this you want
=C2=A0 to make use of that solution for num= erical evaluation of various
=C2=A0 cases.

=C2=A0 Is it safe to use the analytic results (withou= t using a session) in the
=C2=A0 following way, or is there a better way= ?

=C2=A0 #+NAME: analytic-sol
=C2=A0 #+BEGIN_SRC python :session = none :results raw
=C2=A0=C2=A0=C2=A0 from sympy import symbols, sqrt, python, solve
=C2=A0= =C2=A0=C2=A0 x, a =3D symbols("x, a")
=C2=A0=C2=A0=C2=A0 y =3D= solve( x**2 + 2*a*x + 1, x)
=C2=A0=C2=A0=C2=A0 return python(y)
=C2= =A0 #+END_SRC

=C2=A0 #+NAME: numeric-sol
=C2=A0 #+BEGIN_SRC pytho= n :session none
=C2=A0=C2=A0=C2=A0 from sympy import Symbol, sqrt, lambdify
=C2=A0=C2=A0= =C2=A0 import numpy as np

=C2=A0=C2=A0=C2=A0 #+RESULTS: analytic-sol=
=C2=A0=C2=A0=C2=A0 a =3D Symbol('a')
=C2=A0=C2=A0=C2=A0 e = =3D [-a - sqrt(a**2 - 1), -a + sqrt(a**2 - 1)]

=C2=A0=C2=A0=C2=A0 f = =3D lambdify(a, e[1], "numpy")
=C2=A0=C2=A0=C2=A0 t =3D np.r_[1:4]
=C2=A0=C2=A0=C2=A0 return f(t)
= =C2=A0 #+END_SRC

=C2=A0 #+RESULTS:
=C2=A0 | -1 | -0.26794919 | -0= .17157288 |

Regards,
Fede
--001a1133b4345360fd04fbf4fc36--