Re: sum and for loop too slow...



Hi,
1000000 are many, so you should be careful about what you do.

You sum up 27*100000 times more or less the same, so the first
suggestion I have is:devide sum(0:0.001:2000+zeta(i,j)) into
sum(0:0.001:1995)+sum(1995.001:0.001:2000+zeta)

And the first part is not dependent on i,j ...

Titus

"Evan" <evanmason@xxxxxxxxx> schrieb im Newsbeitrag
news:1146661276.745599.229150@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi, can anyone suggest a way to speed up the following bit of code:


pressure = zeros(27,1000000);

for i=1:27
for j=1:1000000
pressure(i,j) = sum(0 : 0.001 : 2000+zeta(i,j));
end
end

'zeta' is an array (27,1000000) containing random floats between -5 and
5. Ideally I'd like to get rid of the 'for' loops as these are taking
all the time, but not sure how/if possible?

Many thanks,

Evan



.



Relevant Pages

  • Re: Total Combinations Matching a Set Sum
    ... Looking at the algorithm quickly, it appears to do the following. ... The question asks for unique sets of six integers that sum to 150. ... This is why the for loops go from the value ... ascending order to our set, the smallest total we can add at this stage ...
    (sci.stat.math)
  • Re: Pythons simplicity philosophy
    ... > As to sum(), when learning string addition, ... the "summing strings" case instead, ... When the sequence is empty, ... 1000 loops, best of 3: ...
    (comp.lang.python)
  • Re: Newbie Question about Fortran speed
    ... > than its counterpart with loops? ... With (extreme) pleasure - it might even open a few eyes enamored with le ... > things like SUM and the DO-ENDDO equivalent take exactly the same time to ...
    (comp.lang.fortran)
  • Re: OK. I *finally* saw a Rachael Ray show...
    ... Be careful. ... items to get rid of that will be hard to let go of later on. ... the list was a gun rack that I made in 9th-grade wood shop. ... So far, the only thing I have regretted giving up, was a 1988 Mercedes ...
    (rec.food.cooking)
  • Trouble with code that is broken over multiple lines (space_)
    ... .CommandText = Array(_ ... Sum(fct_CommissionAccrued.AccruedAmount) AS 'Sum of ... "rID AND fct_CommissionAccrued.CommissionTypeID = ...
    (microsoft.public.excel.programming)

Loading