restriction of a two-parameters function to a one-parameter function

Discussion in 'C++' started by Boris Sargos, Apr 23, 2004.

  1. Boris Sargos

    Boris Sargos Guest

    Hi,

    suppose we have these two functions (not very interesting, but this is for
    clarity) :

    -) a function Primitive that computes at t the primitive of a function
    f :

    double Primitive ( double(*f)(double), t);

    -) a function Indicatrice that defines if the parameter t is in the
    interval [i, i+1] :

    double Indicatrice ( int, double );


    I'd like to write a function Indicatrice_i, restriction of Indicatrice to
    i, like this :

    double (*Indicatrice_i)(double) = Indicatrice(i);


    to use it such this manner :

    for(int i ...;;) {
    // Computation of the primitive at t
    double It = Primitive ( Indicatrice_i , t );
    }

    Someone could help ?

    Thanks.
    Boris.
     
    Boris Sargos, Apr 23, 2004
    #1
    1. Advertising

  2. Boris Sargos

    Buster Guest

    Boris Sargos wrote:
    > Hi,
    >
    > suppose we have these two functions (not very interesting, but this is for
    > clarity) :
    >
    > -) a function Primitive that computes at t the primitive of a function
    > f :
    >
    > double Primitive ( double(*f)(double), t);


    I haven't done much maths in French but I think I "primitive" means
    antiderivative. In that case your description of this function is
    nonsense.

    > -) a function Indicatrice that defines if the parameter t is in the
    > interval [i, i+1] :
    >
    > double Indicatrice ( int, double );


    The characteristic function of the interval.

    > I'd like to write a function Indicatrice_i, restriction of Indicatrice to
    > i, like this :
    >
    > double (*Indicatrice_i)(double) = Indicatrice(i);
    > to use it such this manner :
    >
    > for(int i ...;;) {
    > // Computation of the primitive at t
    > double It = Primitive ( Indicatrice_i , t );
    > }
    >
    > Someone could help ?


    Identifiers do not work like that.

    You could use "std::bind1st (std::ptr_fun (Indicatrice), i)". The type
    of that expression is complicated so (a) it's not straightforward to
    give the function object a name, and (b) you have to modify Primitive to
    accept function objects of any appropriate type.

    #include <functional>
    #include <limits>
    #include <iostream>

    template <typename F> double Primitive (F f, double t)
    {
    // Note: here the function object has a name.
    return std::numeric_limits <double>::quiet_NaN ();
    }

    double Indicatrice (int i, double t)
    {
    return i <= t && t <= i + 1 ? 1.0 : 0.0;
    }

    int main ()
    {
    double t = 0.0;
    for (int i = 0; i != 10; ++ i)
    {
    using std::bind1st;
    using std::ptr_fun;
    std::cout << Primitive (bind1st (ptr_fun (Indicatrice), i), t)
    << '\n';
    }
    }

    --
    Regards,
    Buster.
     
    Buster, Apr 23, 2004
    #2
    1. Advertising

  3. Boris Sargos

    Boris Sargos Guest

    Hi Buster,

    thank you very much for your answer. It's exactly what I was looking for.
    Great !

    > I haven't done much maths in French but I think I "primitive" means

    antiderivative.
    Ok, thank you too for the lesson of english :)

    > In that case your description of this function is nonsense.


    Mathematically, you're right, of course. But we can give it a sense if we
    choose an origin value. For example, suppose F the antiderivative of f. Then
    we can choose F(0) = 0 (if f is well-defined around 0) like this :

    double Primitive ( double(*f)(double), t ) {
    return Simson ( f, t, 0) ;
    }

    Thanks again.
    Boris
     
    Boris Sargos, Apr 23, 2004
    #3
  4. Boris Sargos

    Boris Sargos Guest

    Hi Buster,

    thank you very much for your answer. It's exactly what I was looking for.
    Great !

    > I haven't done much maths in French but I think I "primitive" means

    antiderivative.
    Ok, thank you too for the lesson of english :)

    > In that case your description of this function is nonsense.


    Mathematically, you're right, of course. But we can give it a sense if we
    choose an origin value. For example, suppose F the antiderivative of f. Then
    we can choose F(0) = 0 (if f is well-defined around 0) like this :

    double Primitive ( double(*f)(double), t ) {
    return Simson ( f, t, 0) ;
    }

    Thanks again.
    Boris
     
    Boris Sargos, Apr 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.frontiernet.net
    Replies:
    6
    Views:
    1,129
    news.frontiernet.net
    Apr 16, 2004
  2. Replies:
    1
    Views:
    369
  3. jobs
    Replies:
    1
    Views:
    338
    Mick Walker
    Nov 5, 2007
  4. marc
    Replies:
    3
    Views:
    332
  5. Florian Loitsch
    Replies:
    11
    Views:
    252
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page