Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Re: Formatted Output (Exporting Data)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64433] Re: Re: [mg64415] Formatted Output (Exporting Data)
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 17 Feb 2006 04:11:40 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

myRound[x_,dx_]:=Round[x/dx]*dx;

f[x_]:=x^2;
a=1.2;
b=8.7;
n=11;
t=N[Table[{myRound[x,10^-6],myRound[f[x],10^-6]},
        {x,a,b,(b-a)/n}],6];

Export["foo.d",t,"TSV"];


Bob Hanlon

> 
> From: Troy Henderson <thenders at gmail.com>
To: mathgroup at smc.vnet.net
> Subject: [mg64433] Re: [mg64415] Formatted Output (Exporting Data)
> 
> Bob,
> 
> Thanks again for your reply.  However, I'm not quite happy with the result
> because if I use actual floats for my x range and step size, it's like
> Mathematica doesn't know how to add decimals.  Do you have a solution 
that
> would work for the following:
> 
> f[x_]:=<some function>
> a:=<left endpoint>
> b:=<right endpoint>
> N:=<number of steps>
> Export["foo.d",Table[{x,f[x]},{x,a,b,(b-a)/N}],"TSV"]
> 
> where a,b could be integers or floats and N is always a positive integer.
> 
> Thanks in advance,
> 
> Troy
> 
> On 2/16/06, Troy Henderson <thenders at gmail.com> wrote:
> >
> > That got it Bob.  Thanks alot.
> >
> > On 2/16/06, Bob Hanlon <hanlonr at cox.net> wrote:
> > >
> > > f[x_]:=x^2;
> > >
> > > t=Table[{x,f[x]},{x,-1,1,1/5}]/.
> > >       x_Rational:>N[x,6];
> > >
> > > Export["foo.d",t,"TSV"];
> > >
> > >
> > > Bob Hanlon
> > >
> > > >
> > > > From: "tlhiv" < thenders at gmail.com>
To: mathgroup at smc.vnet.net
> > > > Subject: [mg64433] [mg64415] Formatted Output (Exporting Data)
> > > >
> > > > I'm trying to export the data obtained by evaluating a function at
> > > > certain points.  The method that I'm currently using is:
> > > >
> > > > f[x_]:=x^2
> > > > Export["foo.d",Table[{x, f[x]}, {x, -1, 1, 0.2}], "Table"]
> > > >
> > > > This generates a file "foo.d" that look like:
> > > >
> > > > -1   1
> > > > -0.8   0.6400000000000001
> > > > -0.6   0.36
> > > > -0.39999999999999997   0.15999999999999998
> > > > -0.19999999999999996   0.03999999999999998
> > > > 5.551115123125783e-17   3.0814879110195774e-33
> > > > 0.20000000000000007   0.04000000000000003
> > > > 0.4000000000000001   0.16000000000000006
> > > > 0.6000000000000001    0.3600000000000001
> > > > 0.8   0.6400000000000001
> > > > 1.   1.
> > > >
> > > > I would very much like to have "foo.d" look like:
> > > >
> > > > -1 1
> > > > -0.8 0.64
> > > > -0.6 0.36
> > > > -0.4 0.16
> > > > -0.2 0.04
> > > > 0 0
> > > > 0.2 0.04
> > > > 0.4 0.16
> > > > 0.6 0.36
> > > > 0.8 0.64
> > > > 1 1
> > > >
> > > > and with the delimeter being a TAB instead of a SPACE.  In particular,
> > > > the precision used above is not so good.  I would like everything
> > > > rounded off to, say, 6 significant digits.  An analogous C style
> > > output
> > > > would be something like
> > > >
> > > > fprintf(fid,"%6f\t%6f\n,x,f)
> > > >
> > > > and is performed for each "element" of x.  Can this be accomplished
> > > > easily with Mathematica?
> > > >
> > > > Thanks,
> > > >
> > > > Troy Henderson
> > > > Assistant Professor
> > > > Department of Mathematical Sciences
> > > > 252 Thayer Hall
> > > > United States Military Academy
> > > > West Point, NY  10996
> > > > (845) 938-5649
> > > > http://www.tlhiv.org
> > > >
> > > >
> > >
> > > Bob Hanlon
> > > Chantilly, VA
> > >
> > >
> >
> 
> 


  • Prev by Date: Re: Re: Re: Solve or Reduce?
  • Next by Date: Re: Re: Re: Solve or Reduce?
  • Previous by thread: Re: Formatted Output (Exporting Data)
  • Next by thread: How to hide mathematica code?