From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Stanton Subject: Re: Babel language support for Mathematica Date: Sun, 15 Mar 2015 10:26:48 -0700 Message-ID: <938F6CD6-C9DF-48B2-93EF-95268ABACB5D@haas.berkeley.edu> References: <0E109199-8E68-4B76-A1D9-20105FF0C1D3@haas.berkeley.edu> Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_314F25B4-D46F-43ED-AB3E-D69511216464" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXCJW-0001Xd-EP for emacs-orgmode@gnu.org; Sun, 15 Mar 2015 13:27:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXCJT-0005OF-5Y for emacs-orgmode@gnu.org; Sun, 15 Mar 2015 13:26:58 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:33044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXCJS-0005O1-T3 for emacs-orgmode@gnu.org; Sun, 15 Mar 2015 13:26:55 -0400 Received: by pdnc3 with SMTP id c3so35101249pdn.0 for ; Sun, 15 Mar 2015 10:26:52 -0700 (PDT) In-Reply-To: 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: Yi Wang Cc: emacs-orgmode@gnu.org, John Kitchin --Apple-Mail=_314F25B4-D46F-43ED-AB3E-D69511216464 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Thanks. After a bit of experimentation, I found that you can have a = block outputting several lines, but you need to manually add commas and = carriage returns, e.g., #+BEGIN_SRC mathematica :results output f[x_] :=3D 3*x^2+3; f[8], "\n", D[f[x],x] #+END_SRC #+RESULTS: : 195 : 6*x > On Mar 13, 2015, at 4:16 PM, Yi Wang wrote: >=20 > Dear Richard, >=20 > You can do: >=20 > #+BEGIN_SRC mathematica > f[x_] :=3D x+3; > f[5] > #+END_SRC >=20 > Here are explanations: I actually put everything in the SRC block into = a Print[...]. >=20 > So in the second example, what actually runs is >=20 > Print[f[x_] :=3D x+3 > f[5]] >=20 > This does not return any value. Because what it really does is print = the value of "f[x_] :=3D x+3 f[5]" >=20 > Here is the code: >=20 > (concat > (mapconcat ;; define any variables > (lambda (pair) > (format "%s=3D%s;" > (car pair) > (org-babel-mathematica-var-to-mathematica (cdr pair)))) > vars "\n") "\nPrint[\n" body "\n]\n") >=20 > If anybody has idea to improve it, I will be happy to see and work it = out! >=20 > Best, > Yi >=20 >=20 >=20 >=20 > On Sat, Mar 14, 2015 at 7:09 AM John Kitchin > wrote: > I wonder if this is an output vs value issue on the return of the > block. If you set :results output does anything change? or, is there a > way to specify a return value? or specifically print something? >=20 > Richard Stanton writes: >=20 > > I recently saw this posting about org support for Mathematica. = Thanks for writing this! > > > > Unfortunately, while I can get it to work for simple things (e.g., = 2+3), even slightly more complex things don't seem to work. For example, = suppose I'd like to define a function f(x) =3D x + 3, and then calculate = f(5). In a MMA notebook, if I type > > > > f[x_] :=3D x+3 > > f[5] > > > > I get the answer 8. If I try the same code in an org-mode code = block, here's what happens: > > > > #+BEGIN_SRC mathematica > > f[x_] :=3D x+3 > > f[5] > > #+END_SRC > > > > #+RESULTS: > > : Null > > > > Am I missing something obvious here? > > > > Thanks very much. > > > > Richard Stanton >=20 > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu --Apple-Mail=_314F25B4-D46F-43ED-AB3E-D69511216464 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Thanks. After a bit of experimentation, I found that you can = have a block outputting several lines, but you need to manually add = commas and carriage returns, e.g.,

#+BEGIN_SRC mathematica = :results output
f[x_] :=3D 3*x^2+3;
f[8], "\n",
D[f[x],x]
#+END_SRC

#+RESULTS:
: 195
: = 6*x





On Mar 13, 2015, at 4:16 PM, Yi = Wang <tririverwangyi@gmail.com> wrote:

Dear Richard,

You can do:

#+BEGIN_SRC mathematica
f[x_] :=3D x+3;
f[5]
#+END_SRC

Here are = explanations: I actually put everything in the SRC block into a = Print[...].

So in the second example, what = actually runs is

Print[f[x_] :=3D x+3
f[5]]

This does not return any value. Because what it really does = is print the value of "f[x_] :=3D x+3 f[5]"

Here = is the code:

(concat
     (mapconcat ;; define any = variables
      (lambda = (pair)
(format "%s=3D%s;"
= (car pair)
= (org-babel-mathematica-var-to-mathematica (cdr pair))))
      vars "\n") "\nPrint[\n" body = "\n]\n")

If anybody has idea to improve it, I will be happy to see and = work it out!

Best,
Yi




On Sat, Mar 14, 2015 at 7:09 AM = John Kitchin <jkitchin@andrew.cmu.edu> wrote:
I wonder if this is an = output vs value issue on the return of the
block. If you set :results output does anything change? or, is there = a
way to specify a return value? or specifically print something?

Richard Stanton writes:

> I recently saw this posting about org support for Mathematica. = Thanks for writing this!
>
> Unfortunately, while I can get it to work for simple things (e.g., = 2+3), even slightly more complex things don't seem to work. For example, = suppose I'd like to define a function f(x) =3D x + 3, and then calculate = f(5). In a MMA notebook, if I type
>
> f[x_] :=3D x+3
> f[5]
>
> I get the answer 8. If I try the same code in an org-mode code = block, here's what happens:
>
> #+BEGIN_SRC mathematica
> f[x_] :=3D x+3
> f[5]
> #+END_SRC
>
> #+RESULTS:
> : Null
>
> Am I missing something obvious here?
>
> Thanks very much.
>
> Richard Stanton

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

= --Apple-Mail=_314F25B4-D46F-43ED-AB3E-D69511216464--