MathGroup Archive 2006

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

Search the Archive

Re: How to output float in Fortran form from Mathematica high precision number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63446] Re: How to output float in Fortran form from Mathematica high precision number
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 1 Jan 2006 01:16:00 -0500 (EST)
  • Organization: The Open University, Milton Keynes, U.K.
  • References: <dp5soc$s6h$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Mike Zimnov" <mikezmn at gmail.com> a écrit dans le message de news: 
dp5soc$s6h$1 at smc.vnet.net...
| I'd like to compute Bessel function in Mathematica with high precision
| and output it in form for input it in fortran program.
|
| OutputStream[strm, 1]
| roundReal[x_, n_] := 10.^(-n) Round[10^n x]
| OutputFormData[]
| SetDirectory["D:\TMP"]
| strm = OpenWrite["testbes.txt"]
| prec := 500
| x1 := SetPrecision[1, prec]
| x2 := SetPrecision[2, prec]
| dx := SetPrecision[1, prec]
| n1 := SetPrecision[1, prec]
| n2 := SetPrecision[1000, prec]
| dn := SetPrecision[1, prec]
| Do[Do[Write[strm,
|   FortranForm[MantissaExponent[N[BesselJ[n, x], prec]]],
|   FortranForm[MantissaExponent[N[BesselY[n, x], prec]]]],
| {n, n1, n2, dn}], {x, x1, x2, dx}]
| Close[strm]
|
| gives something like that
| 
List(0.4400505857449335159596822037189149131273723019927652511367581717801382\
| 
22478015547930796592381198254162606413647919983706048911708467231602807674502\
| 
24327981834047353357370821313128426083911211323361641344640781853844152804847\
| 
53267482993683173482977170169722420083977889847208425873705757084398422930770\
| 
74095523362060185360415772992493229757747946150577793631888988863318559886836\
| 
38237174625112208278787141592516308753589377855090803012032268147809601185942\
| 
2171418557117866024107250170328467205798516,0)List(-0.78121282130028871654715\
| 
00000479648205499063907164446078438332461277843915385602167276292380048056346\
| 
10359440695054799546384072763088051135894299724496925283869916704560256547939\
| 
49244470426592964777790550024750925830506854918050627057465600054365011670706\
| 
89836489058471101913575173418974510058673438777241131647428234630931617954458\
| 
98530392572370728528133991215501769790733023504549146823644700048451983374912\
| 
57400947944009136817464165439846747711917028102225916513551033407709857277670\
| 40234678447868,0)
|
| I need in output mantissa and exponent separately as fortran
| understandable numbers
|
| +1.234567890123456e+0000
|
| Any advice will be appreciated
|

Hi Mike,

Remove the *MantissaExponent* built-in function in the do loop as in

Do[Do[Write[strm,FortranForm[N[BesselJ[n,x],prec]],
      FortranForm[N[BesselY[n,x],prec]]],{n,n1,n2,dn}],{x,x1,x2,dx}]

Now, the file testbes.txt contains entries such as

5.249250179911875043030766668811382053978901697865991244145743984947549645865\
19481974988420992782266921860663940624846591187514906582828417212067370735723\
70853319763986023358583373452212155322682729933626274373283986723683169355660\
88439151435101144817905231161824899218459992543037152039242921852343975593284\
55521280556832065292796876955599544769555592399992965967030260229344891508093\
17674027435893638121320048009161995840558683674234178743203501067906698414038\
21217897833329401269601569880652809067e-9-6.780204938731983110100793403327982\
19284021350080773496378842624620244497769376552781303645905275089803836754589\
20919465234705082883252442182321730154348285159917043460755525565726774322778\
06941091840025481355751416416052226734297411870419058690567261791027281212593\
28526154931887816461706293066056509021269961094765733190165338340311158462590\
52448524959850354732948431427966024668933957312706322601386088555717746555379\
24182391179408096064340288883463847380184819422670315611170736850007255003696\
7281e6
2.630615123687453206997853687790502944088570414320727379699886069043482804112\
00605010795138664960329219754990528975572376874564676026099548957092389513980\
43653107950258437779793774289367698320486001067903583998441510657120361255033\
98831316911046963620716026583435076726459047759998955891393620620553207117856\
66984748853950729380026432294360808892323395005018857893007347379561311263149\
77516893135403535213152266386656254979843006169934618206370616000135181124056\
23575226920677388448535799292314413747e-10-1.21618014278689189288130426667971\
14528862383030936526461528888000825171376411509699200814056422633685636875130\
06430003988096740589153327909527398898359993460531682633812438394299774461533\
52823554240712062275647217651446869724290834426939086934040666626330625850992\
26771667940661545358236210268860517425627096971902234590331257572681648175563\
03159253767655905923499175584733685303900995884965237980200527681623360698363\
98234417713944854799513675383845955390564183012172796076470733923559826924512\
71421e8

Best regards,
/J.M. 



  • Prev by Date: Re: Re: Mathematica Programmer vs. Programming in Mathematica/ functions and OOP
  • Next by Date: Re: Lisp-like let in Mathematica?
  • Previous by thread: Re: timer
  • Next by thread: Re: How to output float in Fortran form from Mathematica high precision number