Ah wonderful, thankyou both. Ivar; you're quite right about being able to get rid of the array for t, I was just following term for term the mathematical expression.
Jiahao; your code is indeed much more elegant! Thank you for pointing me in its direction. How efficient is the M::SymTridiagonal type? That conditional sum() is particularly swish. Certainly if the RandomMatrices package is fixed up, I'd use it! Best, Jarv On Friday, 21 March 2014 06:53:35 UTC, Ivar Nesje wrote: > > There is nothing wrong with for loops in julia. I think sturm would be > prettier if you removed `n=length(D)` and instead used `t=zeros(D)` and > `for i=2:length(D)`. Julia creates a Range object for iteration, so the > length function will only execute once. > > countnegatives+=1 > > Do you really need an array for t? It seems to me like you only use the > previous element and could do well with a scalar variable. > >