Skip to main content
edited tags
Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Source Link

Print expressions using local variables in Module without Dollar sign: is that possible

In a Module, I want to print the result of some data fit. I use something like this:

PlotDD[r_, n_, R_] :=
 Module[{d, fit, ft, pl, x}
       ,ft = Table[{d, PythAbst[5, r, n, d, R]}, {d, 0., 10, .1}];
        d =.;
        fit = ToString[Fit[ft, {1, d, d^2}, d]];
        Print["ft[d]=", fit];
        ...
       ];

The output of the print statement is:

ft[d]=                                                   2
0.000402667 + 0.11131 d$28040 + 0.000883443 d$28040

where the 2 in the first line is the exponent of d$28040.

I know, appending a Dollar sign plus some unique number is how local variables of Module are made. But I want it printed without this $-number, I would like it as

ft[d]=0.000402667 + 0.11131 d$ + 0.000883443 d^2

I avoid the exponent in an extra line applying InputForm first. I tried to enclose things in N[#,6] to limit digits to something physically meaningful but the latter does not work for me. Any idea about this?