2

Matlab:

>> format long g
>> A=29357.71
A =
              29357.71

>> B=7623.52 B = 7623.52 >> A+B ans = 36981.23

I got what I entered. I entered .71 in first input and Matlab doesn't ignore human orders (second law of robotics).

Mathematica:

A = 29357.71
29357.7
B = 7623.52
7623.52
A + B
36981.2

In first line it violates second order of robotics: human has entered .71, but Mathmatica think it doesn't matter by it's own reasons.

Is it possible to force Mathematica behave like normal calculator or like Matlab with command format long g?

Using suffix is either insufficient:

A = 29357.71`7
29357.71
B = 7623.52
7623.52
A + B
36981.2

or redundant

A = 29357.71`7
29357.71
B = 7623.52`7
7623.520
A + B
36981.23
MarcoB
  • 67,153
  • 18
  • 91
  • 189
Dims
  • 735
  • 3
  • 12

2 Answers2

7

To get close to Matlab's format long g you can try adding at top of your notebook

 $PrePrint = If[NumericQ[#], NumberForm[#, 15]] &;

Now

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
1

It worked the following way

A = 29357.71``3
29357.71
B = 7623.52``3
7623.52
A + B
36981.23

althoug I don't understand why should I enter 3 but not 2.

Dims
  • 735
  • 3
  • 12
  • That's probably not what you want. "Precision[29357.713]"returns `7.46772` which means less than eight digits of precision, while"Precision[29357.71`]"`` returns MachinePrecision which is double precision (the precision used by Matlab). – Henrik Schumacher Feb 05 '22 at 14:17