emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Stanton <stanton@haas.berkeley.edu>
To: Yi Wang <tririverwangyi@gmail.com>
Cc: emacs-orgmode@gnu.org, John Kitchin <jkitchin@andrew.cmu.edu>
Subject: Re: Babel language support for Mathematica
Date: Sun, 15 Mar 2015 10:26:48 -0700	[thread overview]
Message-ID: <938F6CD6-C9DF-48B2-93EF-95268ABACB5D@haas.berkeley.edu> (raw)
In-Reply-To: <CAJferG-z0bf4kLDFfOeOFz4w+UOOMBOMs_rayzW8MnZk48+yRA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2454 bytes --]

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_] := 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_] := 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_] := x+3
> f[5]]
> 
> This does not return any value. Because what it really does is print the value of "f[x_] := x+3 f[5]"
> 
> Here is the code:
> 
> (concat
>      (mapconcat ;; define any variables
>       (lambda (pair)
> 	(format "%s=%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 <mailto: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) = x + 3, and then calculate f(5). In a MMA notebook, if I type
> >
> > f[x_] := 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_] := 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 <http://kitchingroup.cheme.cmu.edu/>


[-- Attachment #2: Type: text/html, Size: 6036 bytes --]

  reply	other threads:[~2015-03-15 17:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13 23:06 Babel language support for Mathematica Richard Stanton
2015-03-13 23:09 ` John Kitchin
2015-03-13 23:16   ` Yi Wang
2015-03-15 17:26     ` Richard Stanton [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-01-09  3:46 Yi Wang
2014-01-09 10:28 ` Bastien
2014-01-09 10:34   ` Sebastien Vauban
2014-01-09 10:39     ` Bastien
2014-01-09 10:51   ` Yi Wang
2014-01-09 10:55     ` Bastien
2014-01-09 11:03       ` Yi Wang
2014-01-09 11:15         ` Bastien
2014-01-09 11:31           ` Yi Wang
2014-01-09 11:49             ` Yi Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=938F6CD6-C9DF-48B2-93EF-95268ABACB5D@haas.berkeley.edu \
    --to=stanton@haas.berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    --cc=tririverwangyi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).