From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marc Tfardy Newsgroups: gmane.emacs.help Subject: Re: How to use calc functions in own lisp program? Date: Mon, 01 Jun 2009 11:13:18 +0200 Organization: http://onet.pl Message-ID: References: <877hzzgyr4.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1243916907 4521 80.91.229.12 (2 Jun 2009 04:28:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Jun 2009 04:28:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 02 06:28:25 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 1MBLbi-0008Ip-Tl for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Jun 2009 06:28:15 +0200 Original-Received: from localhost ([127.0.0.1]:41838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBLbi-0001s7-1k for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Jun 2009 00:28:14 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.esat.net!colt.net!feeder.news-service.com!newsfeed00.sul.t-online.de!t-online.de!news.nask.pl!news.nask.org.pl!news.onet.pl!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 53 Original-NNTP-Posting-Host: p4fd34be9.dip.t-dialin.net Original-X-Trace: news.onet.pl 1243847599 4726 79.211.75.233 (1 Jun 2009 09:13:19 GMT) Original-X-Complaints-To: niusy@onet.pl Original-NNTP-Posting-Date: Mon, 1 Jun 2009 09:13:19 +0000 (UTC) User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <877hzzgyr4.fsf@gmail.com> Original-Xref: news.stanford.edu gnu.emacs.help:169627 comp.emacs:98196 X-Mailman-Approved-At: Tue, 02 Jun 2009 00:27:51 -0400 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:64887 Archived-At: Jay Belanger schrieb: > 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, When this is true, why provide calc-curve-fit all needed data as call arguments? > 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" This is what I looking for! VERY VERY BIG THANKS! One problem is solved, but here comes the next ;-) The polynomial fit ist the first step. Now I must to compute values on this curve at certain points. In Calc it is very easy. I put the value for 'x' on the stack and press 'sl', Calc ask for variable, I type 'x RET' and get a polynom value for my 'x'. But how can I do in my lisp code? I would be very happy for the right answer! reagrds Marc