unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jay Belanger <jay.p.belanger@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to use calc functions in own lisp program?
Date: Fri, 29 May 2009 20:34:07 -0500	[thread overview]
Message-ID: <877hzzgyr4.fsf@gmail.com> (raw)
In-Reply-To: gvp623$bin$3@news.onet.pl



Marc Tfardy <no@email.com> writes:

> I want to compute the polynomial fitting in my own lisp program. The
> Emacs Calc offers this functionality so my first thought was to use this
> code. But I don't understand the call arguments to calc-curve-fit:

calc-curve-fit is designed to be used as an interactive Calc function,
so it assumes it is being used from the Calc buffer and interacts with
the stack, hence all your error messages.
If you want to use a Calc function from outside of Calc, you'll need to
use the algebraic form of the function; in this case `fit', which is Calc
shorthand for `calcFunc-fit'.  `fit' takes as arguments the curve
model, the variables in the curve model, the coefficients and the data.
(The Calc manual will tell the possibilities for these.)
The Calc functions will assume that their input is in internal Calc
form.  The function `math-read-expr' will take a string and put it in
internal Calc form.  But you probably want to use `calc-eval', which
will take as an argument an algebraic expression (as a string) that you
could use in a Calc session and return the string that represents the
Calc output. For your problem, in Calc you could enter
  fit(a*x^2+b*x+c,x,[a,b,c],[[1,2,3,4],[1.1,4.2,9.2,15.8]])
and get your result, so outside of Calc you can evaluate

  (calc-eval
    "fit(a*x^2+b*x+c,[x],[a,b,c],[[1,2,3,4],[1.1,4.2,9.2,15.8]])")

Evaluating the above gives me

  "0.874999999998 x^2 + 0.53500000001 x - 0.325000000011"



  parent reply	other threads:[~2009-05-30  1:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-29 17:29 How to use calc functions in own lisp program? Marc Tfardy
2009-05-29 19:39 ` Andreas Röhler
2009-06-01  9:18   ` Marc Tfardy
2009-05-30  1:34 ` Jay Belanger [this message]
2009-06-01  9:13   ` Marc Tfardy
2009-06-01 22:06     ` Jay Belanger
2009-06-02  9:01       ` Marc Tfardy

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=877hzzgyr4.fsf@gmail.com \
    --to=jay.p.belanger@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
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).