Starting from:

$24.99

Lists and the Map Function_lab 7 solution

Objectives
• Moreworkwithlists
• Usingthe map function
Activities
1. Use tail-recursion to write a SCHEME function, named list-sum which takes a list of numbers as a parameter andcomputestheirsum. Note: thisfunctiondiffersslightlyfromtheoneyoumustwritetocompletetheproblemset thisweek. Besuretofollowthedirectionsintheproblemsetpreciselywhenpreparingyoursubmission. 2. The mean, or average, of a set of n numbers is the sum of all the numbers divided by the quantity n. Write a SCHEME function, named mean, which takes a list of numbers as a parameter and returns the mean of the numbersinthelist. 3. Themedianvalueofasetofn numbersisthevaluethatseparatesthehalfofhighervaluesfromthehalfoflower valuesintheset. Themediancanbefoundbyarrangingthevaluesinthesetinorderandchoosingthe“middle” value. If there are an even number of values in the set, the median is described as the mean of the two middle values. WriteaSCHEME function,namedlist-median,thattakesalistofnumbersasaparameterandreturns themedianvalueinthelist. 4. Inprobabilityandstatistics,variance,denotedbythesymbolsigmasquared,σ2,isameasureofhow“spreadout” thenumbersinasetare. WriteaSCHEME function,named list-variance,whichtakesalistofnumbersasa parameter anduses thebuilt-in map function andthe list-sum function inquestion 1to computethe variance ofthenumbersinthelist. Itcanbecomputedusingthefollowingfunction: σ2 = 1 n n X i=1 (xi−¯ x)2 where ¯ x isthemeanofthenumbersinthesetand xi isthe ith numberintheset. 5. Alsoinprobabilityandstatistics,thestandarddeviation,denotedbythesymbolsigma,σ,ofasetofnumbersis thesquare-rootofthevarianceoftheset. WriteaSCHEME function,namedlist-stddev,whichtakesalistof valuesasaparameterandusesthe list-variance functioninquestion4tocomputetheirstandarddeviation.

More products