n=89; isprime=%t; for i=2:(n-1) /// \sleftarrow{\normalfont iterate on integers from \verb+2+ to \verb+n-1+} if pmodulo(n,i)==0 then isprime=%f; break;end end clearfun('mprintf') /// @@prerequisite function mprintf(a,b,c) ; endfunction /// @@prerequisite isprime /// \sleftarrow{\normalfont checks result stored in variable \verb+isprime+ } n=16778;///\sleftarrow{\normalfont now illustrate difference in CPU time} timer();///\sleftarrow{\normalfont start \verb+timer+} res=[]; /// \sleftarrow{\normalfont want all the divisors of \verb+n+ } for i=2:(n-1) if pmodulo(n,i)==0 then res=[res,i]; /// \sleftarrow{\normalfont size of vector \verb+res+ increases at each iteration} end end t1=timer();/// \sleftarrow{\normalfont CPU time elapsed from last call to \verb+timer+} res /// \sleftarrow{\normalfont all the divisors of \verb+n+} v=2:(n-1); /// \sleftarrow{\normalfont speeding up computation using matrix computation} timer(); I=find(pmodulo(n,v)==0); /// \sleftarrow{\normalfont indices of divisors using \verb+find+\index{find@\iscilab{find}}} res = v(I)/// \sleftarrow{\normalfont all the divisors of \verb+n+} t2=timer(); [t1,t2] /// \sleftarrow{\normalfont the CPU time of each example}