[Scilab-users] vector operation replacing for loop

Heinz Nabielek heinznabielek at me.com
Thu Nov 8 20:24:25 CET 2018


Great. Thanks. Should have thought of it myself...

Still: is there a vector way?
Heinz

> On 07.11.2018, at 21:06, kjubo <kopac.jakub at gmail.com> wrote:
> 
> 
> 
> Hello,
> 
> precalculate the know values, I gain 40% faster execution time.
> Hope helps a bit...
> 
> BR
> 
> clc, clear, mode(0)
> 
> n=1e6
> Z=grand(1,n,'nor',0,1);
> Z=Z(:);
> r=0.9;
> 
> tic()
> V1=Z;
> for ii=2:n;
>    V1(ii)=r*V1(ii-1)+sqrt(1-r^2)*Z(ii);
> end;
> toc()
> 
> tic()
> V2 = Z;
> k1 = sqrt(1-r^2).*Z;
> for ii=2:n;
>    V2(ii) = r*V2(ii-1) + k1(ii);
> end;
> toc()
> 
> isequal(V1,V2)




More information about the users mailing list