MathGroup Archive 2008

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

Search the Archive

Re: Traditional Ordering of Equations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88821] Re: Traditional Ordering of Equations
  • From: Albert Retey <awnl at arcor.net>
  • Date: Sat, 17 May 2008 23:27:32 -0400 (EDT)
  • References: <g0jk79$ta$1@smc.vnet.net>

Hi,

> - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation?

There is just at this time another active thread about that topic and
the complications of it, check   todays posts or the archive...

> - I want to list all resulting functions in one cell, as can be done using the Print and Fortranform commands. I want the list to look like this:
> 
> 
> FunctionName1 = Function1
> FunctionName2 = Function2
> FunctionName3 = Function3
> etc.
> 
> All these functions were defined earlier in the notebook using the following syntax:
> 
> FunctionName1 = Function1
> 
> I tried writing a new Mathematica function to do this:
> 
> FortranFormulas[ff_] := 
>  Print[HoldForm[ff] "=" FortranForm[ff]]
> FunctionNameList = {NO3inYt, NO3outYt}
> Scan[FortranFormulas, FunctionNameList]
> 
> However, this generates an output like:
> = Function1inFortranForm Function1
> = Function2inFortranForm Function2
> 
> The alternative:
> FortranFormulas[ff_] := 
>  Print[ff] "=" FortranForm[Release[ff]]]
> FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]}
> Scan[FortranFormulas, FunctionNameList]
> 
> generates an output like:
> = FunctionName1 FunctionName1
> = FunctionName2 FunctionName2
> 
> Both are incorrect and in the wrong order.

As others have mentioned in other threads, it is always a good idea to
present a minimal but complete example of code that shows your problem,
otherwise people who spend the valuable time to help you have to even
think about examples themselfs. In this case you are lucky, because an
example was easy to make up :-)

This is how I would do it:

Expr1Name=a^2+b^3;
Expr2Name=5a-b^3+c;
fortrancode=StringJoin[ToString/@Flatten[Map[
{#,"=",FortranForm[#[[1]]],"\n"}&,
{HoldForm[Expr1Name],HoldForm[Expr2Name]}
]]
]

You can copy and paste from the output cell or use something like (be
careful to not overwrite an existing file when executing this!):

Export[
 ToFileName[{$HomeDirectory, "Desktop"}, "formulas.f"],
 fortrancode,
 "Text"
 ]

to create a fortranf source file containing the code.

hth,

albert


  • Prev by Date: Re: overloading times operator
  • Next by Date: Re: overloading times operator
  • Previous by thread: Re: Traditional Ordering of Equations
  • Next by thread: Re: Applying the Integration Function to a List Of