From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jay Belanger Newsgroups: gmane.emacs.help Subject: Re: How to use calc functions in own lisp program? Date: Fri, 29 May 2009 20:34:07 -0500 Organization: mail2news@dizum.com Message-ID: <877hzzgyr4.fsf@gmail.com> References: Reply-To: jay.p.belanger@gmail.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1243647648 14816 80.91.229.12 (30 May 2009 01:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 30 May 2009 01:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 30 03:40:46 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MADYz-0005TR-UU for geh-help-gnu-emacs@m.gmane.org; Sat, 30 May 2009 03:40:46 +0200 Original-Received: from localhost ([127.0.0.1]:40535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MADYz-0004jh-2Z for geh-help-gnu-emacs@m.gmane.org; Fri, 29 May 2009 21:40:45 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.kjsl.com!news.alt.net!news.dizum.com!sewer-output!mail2news-x2!mail2news Original-Newsgroups: gnu.emacs.help,comp.emacs User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) Cancel-Lock: sha1:lgj4IhSaaA9PyZQ8iI/Ka+Jdu18= X-Vpipe: Scanner said ok (av_avast) X-NotAscii: charset=us-ascii X-IP-stats: Incoming Last 2, First 337, in=116, out=0, spam=0 ip=24.116.73.151 X-Originating-IP: 24.116.73.151 X-Abuse-Info: Send abuse complaints to abuse@cableone.net Mail-To-News-Contact: abuse@dizum.com Original-Xref: news.stanford.edu gnu.emacs.help:169592 comp.emacs:98186 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64823 Archived-At: Marc Tfardy 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"