MathGroup Archive 2010

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

Search the Archive

Re: removing non-numeric elements from the table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108033] Re: [mg108016] removing non-numeric elements from the table
  • From: michael partensky <partensky at gmail.com>
  • Date: Sun, 7 Mar 2010 04:01:35 -0500 (EST)
  • References: <201003050933.EAA29417@smc.vnet.net>

Thanks, Bob.
It was very helpful, both technically and ... I missed indeed the issue with
Erf^-1.
Michael

On Fri, Mar 5, 2010 at 7:42 AM, Bob Hanlon <hanlonr at cox.net> wrote:

>
> Restrict the random number to the appropriate range.
>
> Since Erf is on the interval {-1, 1}
>
> Reduce[{1/2 (erf + 1) == 2 r - 1,
>  -1 < erf < 1}, Reals]
>
> 1/2 < r < 1 && erf == 4*r - 3
>
> rnd := RandomReal[{.5, 1}];
>
> Eq := Solve[
>   1/2 (Erf[z/Sqrt[2]] + 1) == 2 rnd - 1, z];
>
> tvR = Quiet[Table[z /. Eq[[1]], {20}]]
>
>
> {-0.932217,-1.90579,1.5922,0.369158,-0.648444,-1.62643,1.48904,0.167125,0.506132,-0.885077,2.16042,-0.0276315,-0.785393,-0.0567042,0.37173,-0.0609761,1.97276,-0.184465,0.961651,-0.263731}
>
> If you can't determine the range
>
> rnd := RandomReal[];
>
> Eq := Module[{soln},
>   While[(soln = Solve[
>         1/2 (Erf[z/Sqrt[2]] + 1) ==
>          2 rnd - 1, z]) == {}, "Whatever"];
>   soln];
>
> tvR = Quiet[Table[z /. Eq[[1]], {20}]]
>
>
> {0.895968,0.250104,0.425207,-1.27241,0.235649,-0.669837,1.78254,0.0853635,-0.463827,-3.41202,-0.923443,-1.75907,-1.46323,0.807043,-0.474897,0.0992433,0.81119,0.407542,-1.13029,0.411251}
>
>
> Bob Hanlon
>
> ---- michael partensky <partensky 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
>
>


  • Prev by Date: Re: removing non-numeric elements from the table
  • Next by Date: Re: Re: Re: coefficients of
  • Previous by thread: removing non-numeric elements from the table
  • Next by thread: Re: removing non-numeric elements from the table