Re: extract elements from a list
- To: mathgroup at smc.vnet.net
- Subject: [mg2856] Re: [mg2841] extract elements from a list
- From: Christian Bennefeld <bennefeld at dkrz.d400.de>
- Date: Wed, 27 Dec 1995 00:49:06 -0500
=========================================================================== === >I've been trying to extract elements from a list x={a,b,c,d,e...} >then square each value and pair it up with the original unsquared value. >These two values form a point (2Dim) and I then try to pair up each >point with a given vertex of {5,25} and use Line[{{5,25},{a,a^2}}] to >graph this thing. > >My main routine (reAlly kinda small) >is...Do[n=x[[i]];Line[{{5,25},{n,n^2}}],{i,10,1}] > >When this is run nothing happens.... > >in this case x={5,5.5,5.4,5.3,5.2...ect} > > >I've been stuck for 2 weeks unable to get this to work and it is driving >me >crazy because it should be sooo easy. =========================================================================== === Hi Chris ... the next line should solve your problem ... just try to think functional .. In[1]:= graph[x_List]:=Map[Line[{{5,25},{#,#^2}}]&,x] In[2]:= graph[{1,2,3,4,5}] Out[2]= {Line[{{5, 25}, {1, 1}}], Line[{{5, 25}, {2, 4}}], Line[{{5, 25}, {3, 9}}], Line[{{5, 25}, {4, 16}}], Line[{{5, 25}, {5, 25}}]} In[3]:= Show[Graphics[%]] Out[3]= -Graphics- Happy new year. Christian bennefeld at dkrz.de -----BEGIN PGP PUBLIC KEY BLOCK----- Version: 2.6.2 mQCPAzDAqPIAAAEEAMIVQSdzO5dijhbMzQxZwAuYJZRXrApR5aIdyFGe7d79fzrg 3kQiEvvG2C7HZzvFS1kzLqhl8FoiapwDKKyFXb5RsGGDfMBdXJvwfXMAWcPh1tH5 q/vabj2PZmkbqS8KHQWf9nuuZq+G2xumC3jrG/5j3CHx5ap/fBVYHn4Sn3ltABEB AAG0J0NocmlzdGlhbiBCZW5uZWZlbGQgPGJlbm5lZmVsZEBka3J6LmRlPg== =p+NK -----END PGP PUBLIC KEY BLOCK-----