Re: Some questions regarding loops and lists.

*To*: mathgroup at smc.vnet.net*Subject*: [mg67224] Re: Some questions regarding loops and lists.*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Tue, 13 Jun 2006 01:07:19 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 6/11/06 at 11:08 PM, thelonias at wildox.net (Eric) wrote: >The first question is regarding algorithm processing for multiple >instances of the same form. For example: solution[n_] function is >created where n_ represents the number of terms in the series-- this >is not constant, but it does increase. The following steps occur >for each usage of the function: >1. Assignment to variable function for plotting purposes. Variable >changes due to number of terms in each series. >2. Plotting the function. ( I guess this is only a visual reassurance >to keep a handle upon the validity of the findroot command.) >3. using the findroot command to provide the lowest zero of the >function. >Presently this is done for each variable function (35 presently) by >hand. Is there a way to automate this process successfully? It sounds like you are trying to find the smallest root of a function with multiple roots. If so, you might find the RootSearch package Ted Ersek created useful. This package is available on the Wolfram MathSource web page. For example, after loading the RootSearch package In[21]:= sol = RootSearch[x/2 + Sin[5*x] == 0, {x, -5, 5}] Out[21]= {{x -> -1.1358415592628808}, {x -> -0.6998127639815517}, {x -> 0.}, {x -> 0.6998127639815517}, {x -> 1.1358415592628808}} Selecting the smallest root can be done by In[22]:= Min[(x/.#)&/@sol] Out[22]= -1.13584 and finally visual verification that these are roots and all of the roots can be done with: Show@Block[{$DisplayFunction = Identity}, {Plot[x/2 + Sin[5 x], {x, -2.5, 2.5}], ListPlot[{x /. #, x/2 + Sin[5 x] /. #} & /@ sol, PlotStyle -> {PointSize[.015], Red}]}]; >The second question is regarding list appending. There is a set of >values calculated which are then placed into a data table. This >table is then used to create a list, and from this list a new list >is created for graphing purposes. The new list contains two values >in each element (x,y), instead of the one it was initially created >with. The new value entered is in the position of x; it is entered >by hand and is simply the original set of values which were >calculated. Ideally, I would think there was a way to simply place >the variables initially calculated into a two dimensional list, use >the first dimension (the only one with a value initially) to >calculate the second dimension elements, and then use that list for >plotting purposes. I hope that gives an idea as to what I am trying >to accomplish. It sounds like you want to plot the results of some function on a set of values against the values. That is plot specific points {x, f[x]}. If so, starting with some random points data = Table[Random[] - .5, {10}]; then squaring each value results = #^2 & /@ data; I can plot the results against the original data by: ListPlot[Transpose@{data, results}]; Alteratively, the last two steps can be combined into a single step with: ListPlot[{#, #^2} & /@ data]; Note, what you are trying to do would be much clearer if you included Mathematica code showing what you have tried. While attachments are not allowed by the group charter, simply copying and pasting from a Mathematica notebook into your message would suffice. But when you do this, you should convert the cells you copy to InputForm before the copy/paste operation. -- To reply via email subtract one hundred and four