Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
6 Replies
|
1 Total Like
View groups...
Share
Share this post:

Error plotting NumberForm?

Posted 3 years ago

Hello, I wrote this code, but it was an error:

ArrayPlot[
 Map[NumberForm[#, {3, 2}] &, {{1.235, 2.568, 3.951}, {4.555, 5.657, 
    6.597}}, {2}]]

I can't imagine where I did wrongly.

POSTED BY: Zhenyu Zeng
6 Replies

Here is a way:

NumberForm[3.14, 2] // ToString // ToExpression

There may be more elegant solutions.

To set the precision of numbers in calculation you can consider SetAccuracy.

POSTED BY: Gianluca Gorni
Posted 3 years ago

I just need it to show that precision. Your idea is good!

POSTED BY: Zhenyu Zeng

The documentation for NumberForm states from the outset that NumberForm PRINTS numbers in a certain format. It is a typesetting construct. There is an explicit warning not to use it in calculation, but it is placed at the very end of the last section (Possible Issues):

10*NumberForm[3.14, 2]

MatrixForm is another typesetting construct that prevents calculation. This behaviour is not intuitive, and it is an obstacle to beginners.

POSTED BY: Gianluca Gorni
Posted 3 years ago

Okay. Let me mark this. But I need to keep NumberForm[,{3,2}] to calculate, how should I do?

POSTED BY: Zhenyu Zeng

NumberForm is to be used only for final display, not for calculation. It is a wrapper that ArrayPlot does not know how to unwrap. The same happens for Plot:

Plot[NumberForm[x^2, {3, 2}], {x, -1, 1}]

I wonder if Wolfram has any plans to make this wrapper transparent to calculation in future versions.

POSTED BY: Gianluca Gorni
Posted 3 years ago

From where did you know NumberForm is to be used only for final display, not for calculation?

POSTED BY: Zhenyu Zeng
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard