Starting from:

$24.99

Pairs and Lists_lab 6 Solution

Objectives
• Workwithpairsandlists
Activities
1. DefineaSCHEME functiontotakeanumber,andreturnapairwiththenumberanditssquare. 2. Define a SCHEME function square-l which will take any list of numbers as input, and returns a list witheachofthosenumberssquared. 3. DefineaSCHEME functionrangethattakesapair(x,y)ofnaturalnumbersasinputandreturnsalist ofallintegersbetweenthem,inclusive. Forexampleif p =(0,10)then (range p) → ’(0 1 2 3 4 5 6 7 8 9 10) 4. Scalar-Vector Multiplication Multiplying a vector by a scalar produces a vector where each componentisthecorrespondingvalueintheoriginalvectormultipliedbythescalarquantity. Forexample:
a(x1 x2 x3)=(ax1 ax2 ax3) DefineaSCHEMEfunction,namedsv-mult,whichtakesalistandavalueasparametersandperforms scalar-vectormultiplicationonthem. 5. Vector Addition Adding two vectors produces a vector where each component is the sum of the correspondingvaluesintheoriginalvectors. Forexample:
(x1 x2 x3)+(y1 y2 y3)=(x1+y1 x2+y2 x3+y3) Define a SCHEME function, named v-add, which takes two lists and performs vector addition on them. Note: vector subtractionisstructuredinthesameway. 6. Thedot productoftwolistsofnumbers(x1 x2 x3)and(y1 y2 y3)is x1∗y1+x2∗y2+x3∗y3 Define a recursive SCHEME function (dot x y) that takes two lists of numbers as its inputs and returns the dot product of those two lists. Do not use the in-built map function. You can assume the twolistshavethesamelength.
1
7. The cross product of two sets represented by lists of numbers X =(x1 x2 x3) and Y =(y1 y2 y3), denotedX×Y,istheset(list)ofallpossiblepairsofnumberswherethefirstnumberineachpairisa memberofthefirstset(list)andthesecondnumberineachpairisamemberofthesecondset(list). In ourexample,X×Y is((x1.y1)(x1.y2)(x1.y3)(x2.y1)(x2.y2)(x2.y3)(x3.y1)(x3.y2)(x3.y3)). Define a SCHEME function (cross x y) which takes two lists as parameters and returns the list of pairsrepresentingthecrossproductoftheitemsinthelists x and y.

More products