help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use calc functions in own lisp program?


From: Marc Tfardy
Subject: Re: How to use calc functions in own lisp program?
Date: Mon, 01 Jun 2009 11:13:18 +0200
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

Jay Belanger schrieb:

> 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,

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]