[Date Index]
[Thread Index]
[Author Index]
Re: Traditional Ordering of Equations
*To*: mathgroup at smc.vnet.net
*Subject*: [mg88818] Re: Traditional Ordering of Equations
*From*: Szabolcs Horvát <szhorvat+mathgroup at gmail.com>
*Date*: Sat, 17 May 2008 05:31:46 -0400 (EDT)
*Organization*: University of Bergen
*References*: <g0jk79$ta$1@smc.vnet.net>
Joost Keuskamp wrote:
> As a beginner in Mathematica I am using Mathematica 6.0 for integration and simplification of a number of functions which I subsequently use in a Fortran program. Now I have two questions which I cannot find the answer to in the documentation or forums:
>
> - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation?
>
> - 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_] :=
This line,
> Print[HoldForm[ff] "=" FortranForm[ff]]
is equivalent to Print[ HoldForm[ff] * "=" * FortranForm[ff] ].
Multiplication is commutative, so Mathematica will automatically sort
the three terms. You probably meant
Print[HoldForm[ff], "=", FortranForm[ff]]
instead.
> 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]]]
Again, the syntax appears to be incorrect here ...
> FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]}
> Scan[FortranFormulas, FunctionNameList]
>
> generates an output like:
> = FunctionName1 FunctionName1
> = FunctionName2 FunctionName2
>
> Both are incorrect and in the wrong order.
>
> I don't know what to do now and was hoping that anyone had a suggestion.. ..many thanks in advance!
>
Here's a way to do this:
First, let's produce some pretty formulae to experiment with:
y = HornerForm[LegendreP[6, x]]
z = TrigExpand[Cos[6 x]]
The key is to set the attribute HoldAll on the function:
ClearAll[fortranFormulas]
SetAttributes[fortranFormulas, HoldAll]
fortranFormulas[ff_] := Print[HoldForm[ff], " = ", FortranForm[ff]]
Now one way to use the function on a list is to wrap all symbols in
Hold, as you did:
fortranFormulas @@@ {Hold[y], Hold[z]}
But it may be more convenient (less typing with long lists) to just use
strings:
Scan[ToExpression[#, InputForm, fortranFormulas] &, {"y", "z"}]
Prev by Date:
**Re: Multiple threads using Mathlink**
Next by Date:
**Re: Re: Re: Testing TOC sidebar palette**
Previous by thread:
**Re: Traditional Ordering of Equations**
Next by thread:
**Re: Traditional Ordering of Equations**
| |