emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] inclusion of #+RESULTS in a source block


From: Federico Beffa
Subject: [O] inclusion of #+RESULTS in a source block
Date: Mon, 16 Jun 2014 16:38:50 +0200

  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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]