MathGroup Archive 2007

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

Search the Archive

Re: a problem about mathematica output

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82419] Re: a problem about mathematica output
  • From: Norbert Marxer <marxer at mec.li>
  • Date: Sat, 20 Oct 2007 05:43:03 -0400 (EDT)
  • References: <ff9rli$4nj$1@smc.vnet.net>

On 19 Okt., 10:59, qwer <chendy0... at gmail.com> wrote:
> I have a puzzle when using mathematica, I want to out put my resuts to
> a .dat file ,but I do not know how to control the digital,  for
> example:
>
> the mathematica code is
>
> f[x_]:=NIntegrate[Sin[y]/y,{y,0,x}];
> OpenWrite["xx.dat",FormatType->TextForm];
> Do[Write["xx.dat",N[x,4],"   ",N[f[x],4]],{x,0.001,1,0.05}];
> Close["xx.dat"];
>
> then in xx.dat you can find
> 0   0.
> 0.05   0.0499931
> 0.1   0.0999445
> 0.15   0.149813
> 0.2   0.199556
> 0.25   0.249134
> .
> .
> but I want it can be written in the form
> 0.000   0.000
> 0.050   0.050
> 0.100   0.100
> 0.150   0.150
> 0.200   0.200
> 0.250   0.249
> .
> .
> It will be look much better!

Hello

All you have to do is to replace N[x,4] by NumberForm[x, {6, 3}]: i.e.

f[x_] := NIntegrate[Sin[y]/y, {y, 0, x}];
OpenWrite["xx.dat", FormatType -> TextForm];
Do[Write["xx.dat", NumberForm[x, {6, 3}], " ",
   NumberForm[f[x], {6, 3}]], {x, 0., 1, 0.05}];
Close["xx.dat"];

Best Regards
Norbert Marxer



  • Prev by Date: Re: a problem about mathematica output
  • Next by Date: Re: Returning rules from functions inside a package context
  • Previous by thread: Re: a problem about mathematica output
  • Next by thread: Re: a problem about mathematica output