|
From: <mw...@gm...> - 2011-01-11 17:00:29
|
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")
I am stuck at how to call f from sum (see call(f) below) and would appreciate your help very much. (I assume f is the string representing the name of the function to call.)
- for (i=a; i<=b; ++i) {
- // calculate f_i(x);
- push(Gcomplex(&tmp, x.real, x.imag)); // todo check the order
- push(Ginteger(&tmp, i));
-
- //call(f); // assume f is the name (string) of the function to call
-
- pop(&tmp);
- ret.real += real(&tmp);
- ret.imag += imag(&tmp);
- }
Thank you very much for your time and effort.
--- specfun.c 2011-01-11 17:40:19.000000000 +0100
+++ specfun.c.orig 2011-01-11 17:37:27.000000000 +0100
@@ -1933,44 +1933,3 @@
push(Gcomplex(&a, x, 0.0));
}
-void
-f_sum(union argument *arg)
-{
- struct value tmp;
- int a, b;
- struct cmplx x, ret, result;
- int i;
-
- (void) arg; /* avoid -Wunused warning */
-
- // pop x
- pop(&tmp);
- x.real = real(&tmp);
- x.imag = imag(&tmp);
-
- // pop b
- if (pop(&tmp)->type != INTGR)
- int_warn(NO_CARET, "expecting an integer as second argument to sum");
- b = tmp.v.int_val;
-
- // pop a
- if (pop(&tmp)->type != INTGR)
- int_warn(NO_CARET, "expecting an integer as first argument to sum");
- a = tmp.v.int_val;
-
- ret.real = 0;
- ret.imag = 0;
- for (i=a; i<=b; ++i) {
- // calculate f_i(x);
- push(Gcomplex(&tmp, x.real, x.imag)); // todo check the order
- push(Ginteger(&tmp, i));
-
- //call(f);
-
- pop(&tmp);
- ret.real += real(&tmp);
- ret.imag += imag(&tmp);
- }
-
- push(Gcomplex(&tmp, ret.real, ret.imag));
-}
--- eval.c 2011-01-11 16:25:01.000000000 +0100
+++ eval.c.orig 2011-01-11 17:38:00.000000000 +0100
@@ -176,8 +176,6 @@
{"atanh", f_atanh},
{"lambertw", f_lambertw}, /* HBB, from G.Kuhnle 20001107 */
- {"sum", f_sum}, /* summation */
-
{"column", f_column}, /* for using */
{"valid", f_valid}, /* for using */
{"timecolumn", f_timecolumn}, /* for using */
--- specfun.h 2011-01-11 16:22:05.000000000 +0100
+++ specfun.h.orig 2011-01-11 17:37:21.000000000 +0100
@@ -61,6 +61,4 @@
void f_inverse_erf __PROTO((union argument *x));
void f_lambertw __PROTO((union argument *x));
-void f_sum __PROTO((union argument *x));
-
#endif /* GNUPLOT_SPECFUN_H */
--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
|