Re: removing non-numeric elements from the table
- To: mathgroup at smc.vnet.net
- Subject: [mg108067] Re: removing non-numeric elements from the table
- From: David Reiss <dbreiss at gmail.com>
- Date: Sun, 7 Mar 2010 05:09:39 -0500 (EST)
- References: <hmqj5p$so5$1@smc.vnet.net>
Here is one approach: Clear[Eq] rnd := Random[]; Eq[] := Module[{soln}, soln = Flatten[{Solve[1/2 (Erf[z/Sqrt[2]] + 1) == 2 rnd - 1, z]}]; If[soln === {}, soln = {z -> Sequence[]}]; soln ]; tvR = Quiet[Table[z /. Eq[], {20}]] --David http://scientificarts.com/worklife On Mar 5, 4:33 am, michael partensky <parten... at gmail.com> wrote: > Hi. I am building a large table filled with the numerical solutions of an equation. > Here is an example, where a normal standard variable is being generated. > > rnd:=Random[]; > Eq:=Solve[1/2 (Erf[z/Sqrt[2]]+1)==2 rnd-1,z]; > tvR=Quiet[Table[z/.Eq[[1]],{20}]]; > > In[187]:= > tvR > > Out[187]= > {0.761439, z /. {}[[1]], z /. {}[[1]], 1.07111, 0.031784, z /. {}[[1]], z/. > {}[[1]], 0.808313, -1.04238, z /. {}[[1]], 0.376982, z /. {}[[1]], 1.06622, > z /. {}[[1]], -0.546643, -0.367224, 0.28111, -0.0606866, z /. {}[[1]], z/. > {}[[1]]} > > What is a nicer way of removing the non-numeric elements? Clearly, it is > possible to filter them out using say NumericQ, but I am looking for > something more elegant (it is apart of a lecture), preferably right while > the Table is being generated. > > Thanks > Michael