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

B

Boris Sargos

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.
 
B

Buster

Boris said:
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';
}
}
 
B

Boris Sargos

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
 
B

Boris Sargos

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top