Re: LISTS and more LISTS
- To: mathgroup at smc.vnet.net
- Subject: [mg2840] Re: LISTS and more LISTS
- From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
- Date: Sat, 23 Dec 1995 03:19:58 -0500
- Organization: University of Colorado, Boulder
In article <4bancs$cqu at dragonfly.wri.com>, cjkelly at bu.edu <cjkelly at bu.edu> wrote: >Enclosed is a little ditty I've been trying to get to work but as is >clear, it has a bug and I have no clue as to what is wrong. > >It is just supposed to extract elements out of a LIST then peform >various operations on these elements one of which is to plot a >series of lines (or rays) starting from the point {25,5} > > > >Clear [f,x] >x={10,8,6,5.5,5.4,5.3,5.2,5.1,5.01,5.001,5.0001,5.0001} >f[x_]=x^2 >Do [Line[{{5,25},{x[[i]],f[x[[i]]]}},{i,Length [x]}]] > You had a number of problems. The first one is, Clear[f] f[x_] := x^2 Using "=" instead of ":=" caused f[x_] to be defined as {10,8,6,...}^2, which isn't what you wanted. Next, your square brackets weren't balanced correctly. To identity problems like this, see if your version of the front end has a "Balance" command in one of its submenus (on the Mac, it's in the "Nesting" submenu of the "Edit" menu). Do[Line[{{5,25},{x[[i]],f[x[[i]]]}}],{i,Length[x]}] ^ this got moved Finally, when you get those problems fixed, you don't get any output from Do. To get output, use Table: Table[Line[{{5,25},{x[[i]],f[x[[i]]]}}],{i,Length[x]}] {Line[{{5, 25}, {10, 100}}], Line[{{5, 25}, {8, 64}}], Line[{{5, 25}, {6, 36}}], Line[{{5, 25}, {5.5, 30.25}}], Line[{{5, 25}, {5.4, 29.16}}], Line[{{5, 25}, {5.3, 28.09}}], Line[{{5, 25}, {5.2, 27.04}}], Line[{{5, 25}, {5.1, 26.01}}], Line[{{5, 25}, {5.01, 25.1001}}], Line[{{5, 25}, {5.001, 25.01}}], Line[{{5, 25}, {5.0001, 25.001}}], Line[{{5, 25}, {5.0001, 25.001}}]} You can plot the result using Show[Graphics[%]] Dave Wagner Principia Consulting (303) 786-8371 dbwagner at princon.com http://www.princon.com/princon