MathGroup Archive 2000

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

Search the Archive

Re: Ordering polynomials from highest to lowest order

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25972] Re: [mg25933] Ordering polynomials from highest to lowest order
  • From: BobHanlon at aol.com
  • Date: Tue, 14 Nov 2000 03:47:05 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 11/10/00 3:44:14 AM, krautschikc at intel.co.jp writes:

>Actually I export the polynomials to another program. So I am using
>FortranForm before I export the List of polynomials to an ASCII file.
>However, after I apply TraditionForm to z37 and then use FortranForm the
>polynomial conversion no longer seem to work as FortranForm canot be applied
>to the Head of TraditionaForm. I tried Apply[Times[#]&,z37]//FortranForm
>to get rid of Head TraditionalForm. That works expect that I now get back
>what I originally started with, e.g. a polynomial from lowest to highest 
order.
>
>Any ideas how to fix this?
>

Use brute force:

tradFortranPoly[poly_, var_] := 
  Module[{cl = Reverse[CoefficientList[poly, var]], n, pairs, ff}, 
    n = Length[cl] - 1;
    pairs = Select[Transpose[{cl, Range[n, 0, -1]}], #[[1]] != 0 &];
    ff = StringReplace[StringJoin[
          If[#[[2]] > 1, 
" + " <> ToString[#[[1]]] <> "*" <> ToString[var] <> "**" <> 
                  ToString[#[[2]]], 
If[#[[2]] > 0, " + " <> ToString[#[[1]]] <> "*" <> ToString[var], 
                  " + " <> ToString[#[[1]]]]
                ] & /@ pairs], {"+ -" -> "- "}];
    If[StringTake[ff, 2] == " +", StringDrop[ff, 3], ff]];

zernike[37] = 1 - 42r^2 + 420r^4 - 1680r^6 + 3150r^8 - 2772r^10 + 924r^12;

tradFortranPoly[zernike[37], r]

"924*r**12 - 2772*r**10 + 3150*r**8 - 1680*r**6 + 420*r**4 - 42*r**2 + 1"

Bob Hanlon


  • Prev by Date: Re: Recursion
  • Next by Date: Re: data from mathematica to be saved in ascii format
  • Previous by thread: Re: Ordering polynomials from highest to lowest order
  • Next by thread: data from mathematica to be saved in ascii format