I have a numerical algorithm. I create a set of x, and y coordinates for points in R^2. Then, I use a rule to see which points are suitable for my purpose, a simple if statement like below:
int N = 0;
for (int i1 = -xN; i1 < xN + 1; i1++)
{
for (int i2 = -yN; i2 < yN + 1; i2++)
{
double x = dist(0) * i1;
double y = dist(1) *i2;
if (sqrt(pow(x, 2) + pow(y, 2)) > 0.8 && abs(x) < 3.1 && abs(y) < 3.91)
{
Points.row(N) = trans(vec{ x, y});
N = N + 1;
}
}
}
Since I change the rule (that is, sqrt(pow(x, 2) + pow(y, 2)) > 0.8 && abs(x) < 3.1 && abs(y) < 3.91) in each example, I was wondering if I could store it as a string variable and then save it with other parameters of the example in a single text file. something like this:
ofstream myfile;
myfile.open("resultEXAMPLE2D01.txt");
myfile << "xN = [" << xN << "];" << endl;
myfile << "N = [" << output.N << "];" << endl;
myfile << "% Condition is " << cond << endl;
myfile.close();
where "cond" should be "sqrt(pow(x, 2) + pow(y, 2)) > 0.8 && abs(x) < 3.1 && abs(y) < 3.91" in this case. So, in "cond" x and y are not variables, I just look at the whole thing as a text/string. but then inside the if statement I want to evaluate some criteria for x and y, so this "cond" should be a function with two doubles as input and a bool as output. Is there some straight forward way to have this kind of type conversion?