Mapping down two lists

• To: mathgroup at smc.vnet.net
• Subject: [mg25179] Mapping down two lists
• From: "John Satherley" <js1 at liverpool.ac.uk>
• Date: Tue, 12 Sep 2000 21:24:23 -0400 (EDT)
• Organization: The University of Liverpool
• Sender: owner-wri-mathgroup at wolfram.com

```Hi MathGroup
I'm trying to sharpen up my functional programming skills and have come
across a problem which is probably very trivial but I can't find a
satisfactory solution.

I have two lists of equal length, one 2 dimensional and the other 1
dimensional:
lst1={{1,2},{2,3},{1,3},......}
lst2={1,2,2,3,4,5.....}

What I want to do is find the difference between lst1[[i,1]] and lst2[[i]]
square it and then sum up all the terms over the length of the list.

It is easy to do this in terms of Tables but I'm trying to find a fast
solution for long lists that uses map and other functional programming
tools.

The best I have come up with is:
Apply[Plus,([#[[1]]&/@lst1-lst2)^2]
but I'm wondering if it is possible to map directly onto the two lists
without first having to extract the elements of the first list? Map seems to
only work down a single list.

I would be most grateful of any hints as to how this might be performed in
an efficient manner.

Thanks for help
Dr. John Satherley
Dept of Chem
University of Liverpool
Liverpool L69 7ZD
UK
js1 at liv.ac.uk

```

• Prev by Date: Re: Mathematica 3.0 & MathReader 4.0
• Next by Date: Re: save a plot
• Previous by thread: RE: Amazing backgrounds
• Next by thread: Re: Mapping Down Two Lists