473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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.

Jul 22 '05 #1
3 1247
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.
Jul 22 '05 #2
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
Jul 22 '05 #3
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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ed Slen | last post by:
Hi, Guys! Have a question about xsd restriction: I am having an element "state" and it could be US state (Which is easy) or Canadian postal code which is easy too (both rules are working...
0
by: Andrew L | last post by:
Hello all, I'm new to XML schema design, and I've got a problem which I need some help with. I have a simple type which describes a list of valid categories. I also have another type which...
1
by: hre1 | last post by:
hello stan, thank you very much for your fast replay! your solution will help to solve my problem. but i try to understand !why! sqc and xmlspy produce this messages: SQC means:TYPE...
3
by: nicolaspujol | last post by:
Hi, wondering if anybody could help me figure how to. in schema, restrict the list of tokens I may have as an attribute value. For example <xs:complexType name="customer"> <xs:sequence>...
3
by: Brett Gerhardi | last post by:
Hi all, can anyone explain why the following isn't valid? <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
0
by: Deep Purple | last post by:
I started with the following error... ------------------------------------------------------- An error occured while loading the schema with TargetNamespace 'http://www.w3.org/2001/XMLSchema'...
5
by: bclark76 | last post by:
I am getting a strange error, maybe someone knows why it is occurring.. I get the following error when I try to validate Untitled8.xml in Altova XMLSPY: Validation error in another file:...
6
by: burkley | last post by:
In XML Schema, is it possible to derive a complex type via restriction and have the new derived type be in a different namespace than the original base type? I've banged on this for 2 days now...
1
by: executeinc | last post by:
Could you some help to define 1. An element with restriction on it's base type (xs:string), limiting maxlength 2. That element also needs two attributes defined on it. Simple restriction is...
3
by: Kai Schlamp | last post by:
Hello! In my schema I have the following: <xs:complexType name="textareaType"> <xs:simpleContent> <xs:restriction base="xs:string"> <xs:attribute ref="label" use="required" />...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.