To reduce an n^2 problem [message #91940] |
Mon, 21 September 2015 14:55  |
simulana
Messages: 15 Registered: August 2012
|
Junior Member |
|
|
Let's say I have a gravitational potential problem in 2D array (or any Poisson problem), where the potential at each cell is determined by the sum of the contributions of all other cells, of the form m/r. This is naturally an n^2 problem, with a simple solution requiring a for loop over each cell and determining the distances from every other cell and then the sum of their contributions.
First question - has anyone ever done this using IDL? I know that multigrid solvers and FFT solvers have been written into many other languages to solve this problem. But, it seems like a direct solution could be obtained using IDL's array capabilities (a la distance_measure). What remains is serious indexing trouble, either with mapping the distance_measure results back to a 2D array (since it must be correlated to density), or if you skip distance_measure altogether and just attempt to make an (nx,ny,nx*ny) array for all of the distances.
Second question - even if you haven't done this in IDL, here is a thought experiment. Would using IDL arrays actually reduce this problem below n^2?
Thanks for your time.
|
|
|