A case where FOR loops are unavoidable? [message #51577] |
Mon, 27 November 2006 14:19 |
gknoke
Messages: 9 Registered: September 2006
|
Junior Member |
|
|
Hi all, I'm trying to setup an array for the computation of a rather
tricky multidimensional function, but I'm seeing no way around using
FOR loops in its creation. I've been trying to figure out an
appropriate vector solution, but so far I'm drawing a blank.
The equation goes as follows:
f(x, b1, b2, p) = alog((1/b1)*(1-p)*exp(-x/b1) + (1/b2)*p*exp(-x/b2))
Here x is a vector roughly of length 2^20, b1 and b2 are roughly
100-1000 elements, and p is roughly 10-50 elements. I realize that
this is a larger array than is likely to fit in memory, but what I'm
really after is the sum of this function in the x dimension, i.e. the
final output should be something like:
f_out(b1,b2,p) = total(f(x,b1,b2,p), 1)
My approach to this is to loop over b1, b2, and p to take advantage of
being able to use the total function to keep the array size manageable,
like so:
for k=1,np
for i=1,nb1
for j=1,nb2
f_out(i,j,k) = total(f(x, b1[i], b2[j], p[k]), 1)
etc. etc.
This works, but I'm wondering if there are any better approaches?
|
|
|