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?
Block
instead ofModule
. This will clear the values of the variables that you specify (and restore the old values when done), but not create new unique identifiers for them. Also, usingLinearModelFit
orNonlinearModelFit
instead ofFit
gives you better-formatted output directly. $\endgroup$d /: MakeBoxes[d, StandardForm] = "d"
at the top of your Module. $\endgroup$PlotDD[r_, n_, R_] := Module[{d, fit, ft, pl, x}, d /: MakeBoxes[d, StandardForm] = "d"; ft = Table[{d, PythAbst[17, r, n, d, R]}, {d, 0., 10, 0.1}]; fit = ToString[InputForm[N[Fit[ft, {1, d, d^2}, d], 6]]]; Print["ft[d]=", fit]; ];
but I still got print results withd$8586
and withd$8586^2
. - Any idea about how to coerce the numbers to 6 relevant digits? $\endgroup$