i have to talk about my favorite set of tools in logo again: thanks to brian we have map and friends map applies a function to a list of arguments. rseq (now in ucblogo and mswlogo) gives equally spaced sequences. let us look for the maximum of x*x*(1-x) on the interval from 0 to 1 map [? * ? * (1 - ?)] rseq 0 1 21 gives the list of values for 0, 0.05, 0.1, 0,15 .... we want to see the input producaing a value and tha value itself, therefore we do: map [list ? (? * ? * (1 - ?))] rseq 0 1 21 now we want to find the input-value pair with the maximal value iwill reuse some of the things from the pirate project we need max of a list of values to max :a :b output ifelse :a < :b [:b] [:a] end to max.list :l if (count :l) = 2 [output first :l] output reduce "max :l end to maxfind :funlist localmake "ourmax max.list map [first butfirst ?] :funlist output filter [:ourmax = first butfirst ?] :funlist end with these tools maxfind map [list ? (? * ? * (1 - ?))] rseq 0 1 21 will give the maximal value if you need functions with an arugment of x (or any other named argument) you also can do maxfind map [[x] list :x (:x * :x * (1 - :x))] rseq 0 1 21 this is rather close to how one would express the definition of a maximum in mathematical notation, and at the same time it works. there si one programming language which gets even closer to mathematical notation for this type of example, it is ISETL -- Erich Neuwirth <neuwirth@smc.univie.ac.at> Computer Supported Didactics Working Group, Univ. Vienna Visit our SunSITE at http://sunsite.univie.ac.at --------------------------------------------------------------- Please post messages to the Logo forum to logo-l@gsn.org. Mail questions about the list administration to logofdn@gsn.org. To unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home