Boost logo

Boost :

From: Martin Weiser (weiser_at_[hidden])
Date: 2002-10-24 03:58:19


On Mittwoch, 23. Oktober 2002 18:58, Victor A. Wagner, Jr. wrote:
> At Wednesday 2002/10/23 03:23, Martin Weiser <weiser_at_[hidden]> wrote:
> >On Mittwoch, 23. Oktober 2002 11:34, Victor A. Wagner, Jr. wrote:
>
> [deleted]
>
> > > >It seems as if given only dx and dt, the only possibility to
> > > > implement such a function is the explicit Euler scheme, i.e.
> > > > rectangular integration - unless you store computed points and
> > > > perform some multistep method. But I gather this would require an
> > > > interface change.
> > >
> > > I can't see why, method can include the information
> >
> >Let me be more detailed in order to ensure we're talking about the
> > same things. Omitting genericity,
> >
> >double integrate_step(double dx, double dt) {
> > // compute increment from dx and dt. Only possibility:
> > return dx*dt;
>
> //not really.... for example (delete the previous line (return dx*dt;))
>
> static double x = 0.0;
> static double old_x, old_dt;
> static int step = 0;
> static bool first_time = true;
> double new_x;
>
> if (first_time) {
> new_x = dx * dt;
> first_time = false;
> } else {
> //perform some multistep method
> new_x = multistep(old_x,old_dt,x,dt);
> }
> old_x = x;
> old_dt = dt;
> ++step; // not sure what this does
> return x += new_x;
>
> >}
>
> Now, I've made NO changes to what was in the header file describing the
> function.

True, but I don't think static variables in the free function are a viable
option. It's limiting to do at most one integration at a time.

> I don't see how one could say the "interface" changed.

Well, if the semantics is counted as part of the interface, the
abovementioned limitation is quite a drastic change.

> Of course, I prefer the function object idea as you show below, but I
> don't follow your comment about "changing the interface".
> Unless you're referring to the obvious change from a free function to a
> member function, but somehow I don't think that's what you meant.

I just wanted to point out that the interface must allow for storing
previous values - either in a function object (preferred) or directly
given as parameters (cumbersome) - or as static variables (which I think
is dangerous).

But we're getting into the nitpicking area here.

Yours,
Martin

-- 
Dr. Martin Weiser            Zuse Institute Berlin
weiser_at_[hidden]                Scientific Computing
http://www.zib.de/weiser     Numerical Analysis and Modelling

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk