|
From: Ethan M. <merritt@u.washington.edu> - 2011-01-11 21:32:11
|
On Tuesday, January 11, 2011 12:37:42 pm mw...@gm... wrote:
> > Ethan Merritt <merritt@u.washington.edu> wrote:
> > On Tuesday, January 11, 2011 09:00:19 am mw...@gm... wrote:
> >> Hi,
> >>
> >> I want to add finite summation to gnuplot, that is a function sum(a, b,
> >> x, f), where a, b (int) are the summation boundary, x (double) is a
> >> varialbe, f (string) is the name of the function to eveluate a term.
> >> Example usage:
> >>
> >> f(n, x) = sin(n*x)
> >> plot sum(1, 10, x, "f")
> >
> > That pair of commands does not seem to be compatible with your
> > description. How is the code to know there is a second parameter to
> > f()? And where would it get this second parameter from?
>
> sum requires its 4-th parameter to be the name of a 2 parametric function. Before the call to f in sum, two values are pushed. I think I missed the point of what you were trying to tell me.
I guess I don't understand what you are trying to do.
(1) I thought f was a string parameter passed to f_sum, containing the name
of a user-defined function. But your code never pops it as a parameter
and instead refers to it as a string constant "f". That may be just for
debugging but it contradicts your definition of the sum() function so I'm
not sure.
(2) I still don't understand what is "n", or why you want to pass a second
parameter to f.
Are you thinking that you want an infinite class of functions f_n(x)?
That would take a lot of work to support.
> With your generous help I was able to get stuck a little bit later. I assume its related to your initial comment about the parameters of f. I thought, that I have to push two values (int n, cmplx x) onto the stack and then execute_at(..). I could verify (by calling pop()/more_on_stack() repediatly) that execute_at(..) doesn't pop values from the stack. In fact I believe that initially the stack containes two values (n, x) and then execute_at(..) adds another. Did I do it wrong? How can I pass n, x to the function if not by pushing them?
You either have to duplicate the relevant parts of f_calln(),
or else you have to set up all the bookkeeping variables needed by
f_calln() and call f_calln() itself to do the work.
Ethan
|