1. ## Dynamic 2D array

Hi

I am trying to make a Monte-Carlo simulation in C++, and in that respect I need to store two values x and y in a 2D array.

Here is the situation: I have a loop running until some condition is satisfied. For ever iteration I want to write a pair of values (x, y) to my array, but the problem is that I don't know how many iterations there will be until the loop stops.

So my question is how I can make a 2D-array dynamically?

Thanks for any help.

Best,
Niels.

2. Have you considered using std::vector, this will grow as required.

Jim

3. Are the ranges of x and y somehow dependent on your number of iterations?

I thought the general idea of MC was "throwing random darts at a dartboard" and then seeing how many meet some criterion (distance from centre) to give you some approximate answer to some value (say PI).

4. Originally Posted by jimblumberg
Have you considered using std::vector, this will grow as required.

Jim
Thanks, they did the trick.

Originally Posted by Salem
Are the ranges of x and y somehow dependent on your number of iterations?

I thought the general idea of MC was "throwing random darts at a dartboard" and then seeing how many meet some criterion (distance from centre) to give you some approximate answer to some value (say PI).
They do depend on the number of iterations (on average) in my case. Yes, MC can be used for stuff like that (evaluating integrals numerically, estimating Pi, etc..), but those are merely simple examples of what stochastic processes can be used for.

Thanks for the help.

Best,
Niels.