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: Jay Belanger
Subject: Re: How to use calc functions in own lisp program?
Date: Mon, 01 Jun 2009 17:06:28 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (gnu/linux)


Marc Tfardy <no@email.com> writes:
> Jay Belanger schrieb:
..
>> 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?

I don't know. :(

> This is what I looking for! VERY VERY BIG THANKS!

You're welcome. :)

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

You could use `subst', which takes the form "subst(expr,var,value)".
(Actually, instead of a variable any expression can be substituted for.)
So, if you want the best fit curve evaluated at x=2, for example,
you could use
 (calc-eval
     
"simplify(subst(fit(a*x^2+b*x+c,[x],[a,b,c],[[1,2,3,4],[1.1,4.2,9.2,15.8]]),x,2))")
or even
  (string-to-number ...above...)

(Of course, depending on what else you want Calc to do, it might be more
efficient to write a lisp program that will do the curve fitting.)

Jay



reply via email to

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