Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Searching for a function.' topicStudent Support Forum > General > Archives > "Searching for a function."

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
01/21/13 7:38pm

Test this carefully before you depend on it.

In[1]:= numbers={1,2,5,9,4,2,1,10,12,1};
runs=1;
increasing=numbers[[1]]<=numbers[[2]];
For[i=1,i<Length[numbers],i++,
Which[
increasing&&numbers[[i]]>numbers[[i+1]], runs++;increasing=False,
Not[increasing]&&numbers[[i]]<numbers[[i+1]], runs++;increasing=True
]];
runs

Out[5]= 4

With 10^4 values it finishes in a fraction of a second.

URL: ,

Subject (listing for 'Searching for a function.')
Author Date Posted
Searching for a function. Student Konrad 01/21/13 4:23pm
Re: Searching for a function. Bill Simpson 01/21/13 7:38pm
Re: Searching for a function. Bill Simpson 01/22/13 01:11am
Re: Searching for a function. yehuda 01/22/13 04:39am
Re: Searching for a function. Student Konrad 01/22/13 3:22pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic