|
From: Ethan A M. <sf...@us...> - 2016-01-15 18:40:11
|
On Friday, 15 January, 2016 17:54:37 pl...@pi... wrote:
> On 15/01/16 17:40, Ethan A Merritt wrote:
> > On Friday, 15 January, 2016 11:38:01 pl...@pi... wrote:
> >
> > > Hi ,
> >
> > >
> >
> > > I accidentally forgot a * operator when plotting a function. This seems
> >
> > > to have injected an udefined fn into the name space
> >
> > >
> >
> > >
> >
> > > twopi=2*pi
> >
> > >
> >
> > > gnuplot> plot datafile" u ($1/365.25+1970):2 w l, cos (twopi(x)/p3) +0.05
> >
> > > undefined function: twopi
> >
> > >
> >
> > > User-Defined Functions:
> >
> > > cos1(x)=a1*cos(twopi*(x-phi1)/p1)
> >
> > > cos2(x)=a2*cos(twopi*(x-phi2)/p2)
> >
> > > cos3(x)=a3*cos(twopi*(x-phi3)/p3)
> >
> > > triple(x)=c+cos3(x)
> >
> > > twopi is undefined
> >
> > >
> >
> > >
> >
> > > gnuplot> print twopi
> >
> > > 6.28318530717959
> >
> > >
> >
> > >
> >
> > > Now it won't stop crapping on about "twopi is undefined", even though I
> >
> > > have plotted something else and make no reference to it.
> >
> > >
> >
> > >
> >
> > > All I can find to clear it is to quit gnuplot.
> >
> > >
> >
> > > Has this , as it seems, injected an undeclared function into the name
> >
> > > space ?
> >
> > >
> >
> > > How to clear it more elegantly, is this a bug?
> >
> > There is currently no way to clear or delete any user-provided function.
> >
> > That is true for your well-defined functions as well as your undefined
> >
> > function. The "undefine FOO" command only looks for FOO as a variable
> >
> > name not as a function name.
> >
> > If you want to reset the entire namespace you can use "reset session".
> >
> > Of course that will clear everything, not just the undefined function.
> >
> > Ethan
> >
>
> Thanks Ethan,
>
> the main point was, is this a bug?
>
> how did I manage to register an undefined function simply by trying to (
> accidentally ) use it in a plot command?
>
> How does that become a function definition, right or wrong ?
gnuplot allows you to refer to a function before you define it.
Consider:
g(x) = f1(x) + f2(x)
In order to store the evaluation template for g(x) it has to reserve
slots for f1() and f2() even if they have not been defined yet.
If you say "show fun" at this point you will see
User-Defined Functions:
g(x) = f1(x) + f2(x)
f1 is undefined
f2 is undefined
Issuing a plot command triggers the same thing implicitly.
The program constructs a template for how to evaluate the values
being plotted, reserving a slot for any functions that are invoked.
If it turns out that one of those functions is not yet defined then
the plot will fail, but just as in the above example it leaves
an entry in the table of functions that can be filled in later.
You can see this at work in the following admittedly bizarre
plot command that plots f(x) twice but redefines it in between:
plot f(x)=sin(x) f(x), f(x)=cos(x) f(x)
That works because both curves in the plot are evaluated using
the template "f(x)" but the definition of "f()" has changed
between the two evaluations of the same template.
So - not a bug.
Ethan
|