MathGroup Archive 1997

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

Search the Archive

Re: How to get E**(-x), not 1/E**(x) ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9811] Re: [mg9717] How to get E**(-x), not 1/E**(x) ?
  • From: David Withoff <withoff>
  • Date: Fri, 28 Nov 1997 05:35:24 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

> Hello,
>
> When I input an expression which containing natural logarithm exp(-x),
> where x is a symbol,  and I want to get the fortran form output. For
> example, If the input is :
>
>      FortranForm[ y*Exp[-x] ]  where y is an arbitrary expression.
>
> the output will be :
>
>      y/E**(x)
>
> Of course it is not wrong. But if I copy the output into a Fortran
> program, when x is assigned a enough large positive value , the Fortran
> program will overflow. But if it is y*E**(-x) , there will be no
> problem. You may say that why not change y/E**(x) to be y*E**(-x)
> yourself , It is because I have a great number of this kind of
> expressions. It is a hard work to change them one by one and it is very
> easy to make mistakes.
>
> So can you tell me how to force Mathematica to give me y*E**(-x), not
> y/E**(x) ??
>
> Many thanks for your help
>
> Zhanwen Ma
>
> Oak Ridge National Lab.
> Physics Division
>
> Oak Ridge ,TN 37831-6354

Here is one possibility:

In[1]:= Unprotect[Times] ;

In[2]:= Format[p_Times, FortranForm] :=
            With[{new = Map[Replace[#, _^_ -> HoldForm[#]] &, p]},
                new /; new =!= p]

In[3]:= FortranForm[ y*Exp[-x] ]

Out[3]//FortranForm= y*E**(-x)

There are are lots of other possibilities.

Dave Withoff
Wolfram Research


  • Prev by Date: Re: Trivial integral freezes 3.0
  • Next by Date: Re: 2nd Try!
  • Previous by thread: Re: How to get E**(-x), not 1/E**(x) ?
  • Next by thread: Re: How to get E**(-x), not 1/E**(x) ?