I'm trying to integrate a simple function (x*y) using the Romberg method.(adsbygoogle = window.adsbygoogle || []).push({});

Question 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-y->[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

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;

}

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C/++/# How to integrate when one of the limits is a variable?

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads for integrate limits variable |
---|

If statement for Monte Carlo integration |

Programming succesive trapezoidal integrator |

Python Numerical integration 'quad' error |

Numerical Integration with variable limits MATLAB |

Python Integrating to Infinity Numerically |

**Physics Forums | Science Articles, Homework Help, Discussion**