C++ doubts in global variables and numerical integration

I’m trying to integrate a simple function (xy) using the Romberg method. But I’m having 2 problems.
Problem 1:
I want to integrate only x and maintain the argument y present in the rest of calculation, like a global variable. In fortran 77 I would use common.
Question 2:
How to integrate using arguments in the limits. For example:
f(x,y)=x
y
intervals-y->[x,1]
intervals-x->[0,1]

PS: Integration using values in the limits are okay.

Routine obtained from https://people.sc.fsu.edu/~jburkardt/cpp_src/nintlib/nintlib.html

// Just a part of the code
double f1(int dim_num,double x[]){
double *a;
double *b;
int dim;
int eval_num;
int ind;
int it_max = 3;
double result;
int *sub_num;
double tol;
//
// Set the integration limits.
//

a = new double[dim_num];
b = new double[dim_num];
sub_num = new int[dim_num];

a[0]=0.0; <- x[0] or x[1]?
b[0]=1.0;
tol = 0.0001;
for ( dim = 0; dim < dim_num; dim++ )
{
sub_num[dim] = 20;
}
result = romberg_nd ( f0, a, b, dim_num, sub_num, it_max, tol,
&ind, &eval_num );

delete [] a;
delete [] b;
delete [] sub_num;
// cout << result << endl;
return result;
}

double f0(int dim_num,double x[]){
double value;
value=x[0]*x[1];
return value;
}

See the old “Boundary integral” and " Non-rectangular region integration" threads.

Thanks again, Wile!:slightly_smiling_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.