Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mapping down two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25220] Re: [mg25179] Mapping down two lists
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 15 Sep 2000 02:21:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On first sight, I think that perhaps the simplest approach would be:

In[1]:=
lst1 == {{1, 2}, {2, 3}, {1, 3}, {3, 7}, {2, 9}};
lst2 == {1, 2, 2, 3, 4};

In[3]:=
Plus @@ ((Transpose[lst1][[1]] - lst2)^2)
Out[3]=
5

This doesn't require any notion of functional programming other than Apply.
 Of course you have to extract the first element of each element of the first
 list, but this can't be helped anyway. However, Transpose is an extremely
 fast operation.

Tomas Garza
Mexico City

John Satherley wrote:

> 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.



  • Prev by Date: Re: Add the Logarithms (error in integral)
  • Next by Date: Re: writing mathematica script files for the math kernel under linux
  • Previous by thread: Re: Mapping Down Two Lists
  • Next by thread: Re: Mapping down two lists