0

I'm using the NumberForm command inside a Manipulate environment, and in some special cases Mathematica gives a pesky and mostly useless warning message :

NumberForm::sigz: In addition to the number of digits requested, one or more zeros will appear as placeholders.

Is there a way to tell mathematica to not give any of these useless warnings ?

I'm using NumberForm just to round some output numbers, with a fixed number of digits, like this : NumberForm[x, {4, 3}].

Also, is there a way to round the labeled numbers which are shown next to a Manipulate slider ?

Update : Here's a MWE which replicates my problem :

Afunction[r_, x_, y_] := -x/r + (y^2 - 1)/(2 r^2)

Acurve[x_, y_] := Plot[{Afunction[r, x, y], (x^2 - 1)/2}, {r, 0, 10}, PlotRange -> {{0, 10}, {-1.5, 1.5}}]

someInfo[x_, y_] := If[(0 < x < 1 && y > 1), Text[Style[StringJoin["Just a test :\n\n", "r = ", ToString[NumberForm[x/(1 - x^2), {5, 4}]], " km"]], {5, -1.25}], {}]

Manipulate[Show[Acurve[x, y],
PlotRange -> {{0, 10}, {-1.5, 1.5}},
AspectRatio -> 1,
Frame -> True,
Epilog -> someInfo[x, y]],

Row[{
    Control[{{x, 0.8}, -1, 2, 0.001, Appearance -> {"Labeled"}}],
    Spacer[124],
    Control[{{y, 1.5}, 0, 15, Appearance -> {"Labeled"}}]
}]]

The code compiles fine and works as excepted. However, open the first slider to enter a number by hand for "x", and enter something like x = 0.9999999. Then you should get a warning message.

What is the problem with my code ?

Cham
  • 4,093
  • 21
  • 36
  • 1
    you may use Quiet to prevent message but what is your Manipulate code? I cannot reproduce the problem. – garej Feb 06 '16 at 14:30
  • the answer to the second part of the question is here – garej Feb 06 '16 at 14:33
  • Thanks garej. My manipulatye code is pretty complex, and would be hard to reduce to a MWE. Do the Quiet command applies to ALL error messages as well ? And where should I put that Quiet command in the code ? Anywhere ? – Cham Feb 06 '16 at 14:44
  • no, it, like any function, applies to the expression, wrapped in it. If it is NumberForm poses problem than Quiet@NumberForm[...]. Or whatever. You may prevent all messages by Quiet@Manipulate[...]. – garej Feb 06 '16 at 14:49
  • Ah, cool ! I'm learning a new Mma trick each day ! 8-) I'll try the Quiet command to manipulate to see if it solves my problem. – Cham Feb 06 '16 at 14:52
  • I just tried the Quiet at several places, and it doesn't prevent the warning messages. I used it at the Manipulate, and seperately at all the NumberForm calls. I'll try to make a MWE. – Cham Feb 06 '16 at 14:58
  • I made a MWE but I'm unable to reproduce the warnings with it. – Cham Feb 06 '16 at 15:08
  • 1
    make Off[NumberForm::sigz]. Off is another option to turn of warnings. See here. – garej Feb 06 '16 at 15:32
  • I just replicated the issue with a simple MWE. I'm updating my question. – Cham Feb 06 '16 at 15:35
  • Where and how do I use that command ? This is new to me. – Cham Feb 06 '16 at 15:53
  • I just added that command at the start of the code, and it appears to work. However, the number output may turn out to be in scientific notation (something like 5.00000 X 10^7), and the info is garbled on the graphic, because of the exponent. What should I do there ? – Cham Feb 06 '16 at 15:57
  • the problem with Quiet might be a bug by the way - see related post – garej Feb 06 '16 at 17:23

1 Answers1

1

To address the issue use some Off[NumberForm::sigz] in Manipulate[...]. It is also better to use simple Epilog with Text[Row[...] (code below):

enter image description here

Some code picture: enter image description here

garej
  • 4,865
  • 2
  • 19
  • 42
  • Yes, the number is badly shown at bottom of the graphics. 5.0000 X 10^7 should be aligned with the = sign, and the 7 exponent should be properly placed. I get the same with my version. – Cham Feb 06 '16 at 16:14
  • @Cham, the problem in using ToString. Play around with this code: someInfo[x_, y_] := If[(0 < x < 1 && y > 1), Text[Row[{"Just a test :\n\n", "r = ", NumberForm[x 5.00000*10^7, {5, 4}], " km"}], {5, -1.25}], {}] – garej Feb 06 '16 at 16:59
  • Using the combination Manipulate[Off[NumberForm::sigz];... and NumberForm[x/(1 - x^2), {5, 4},ExponentFunction->(Null&)]] appears to solve all issues. – Cham Feb 06 '16 at 17:01
  • garej, the problem with your suggestion (to use Row[{"... ) is that I need to put some parts like Subscript[[ScriptCapitalJ], c], so I need to use the StringJoin and ToString commands. Unless there's another way that I don't know. – Cham Feb 06 '16 at 17:07
  • Yes, thanks a lot for all the help, garej, it's really appreciated ! Here's what I'm achieving with the JoinString command : http://postimg.org/image/xmai9uhtx/ Could you do this with the Row command ? – Cham Feb 06 '16 at 17:29
  • garej, one more question : how do you change the font and size of the text, in your Row comand ? – Cham Feb 06 '16 at 17:47
  • 1
    I found it ! For Row, you add BaseStyle -> {FontSize -> 12, FontFamily -> "Helvetica"} for example, as an option. It works great, and the code is less messy that using all the StringJoin. I think I'm having it right now, finally ! Geez, Mathematica isn't obvious to use... – Cham Feb 06 '16 at 18:09