Solve Mathematica Truncation Problem with Vectors of Numbers

  • Context: Mathematica 
  • Thread starter Thread starter docfan123
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

The discussion addresses a truncation issue in Mathematica when displaying vectors of numbers with more than six decimal digits. The user initially encounters problems with the decimal parts of certain numbers not being displayed in the output table. The solution involves using the NumberForm[] function to format the numbers correctly. By applying Map[NumberForm[#,{8,2}]&,Mat,{-1}], the user successfully formats the output, ensuring all decimal parts are displayed as intended.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of vector operations in Mathematica
  • Knowledge of formatting functions such as NumberForm[]
  • Basic experience with table generation in Mathematica
NEXT STEPS
  • Explore advanced formatting options in Mathematica using NumberForm[]
  • Learn about the Transpose[] function for manipulating data structures
  • Investigate other Mathematica functions for data presentation, such as Grid[] and TableForm[]
  • Study error handling in Mathematica to manage unexpected output issues
USEFUL FOR

This discussion is beneficial for Mathematica users, data analysts, and anyone involved in numerical computations who needs to ensure accurate and formatted output of numerical data.

docfan123
Messages
2
Reaction score
0
I've this problem i don't know how to solve ... I declare this two vectors of numbers(a shortened list) and then when I make a table with them for further calculation, Mathematica truncates some of them, not showing the decimal part of the numbers with more than 6 digits ... The code is:

VX = {-12, -11, -10, -9, -8, -7, -6};
VY = {891628, 528522.1, 297984, 158106.1, 77812, 34804.5, 13729.6};

Points = {VX, VY};
Mat := Transpose[Points];

Print["Table of values: "];
Print[TableForm[Mat, TableHeadings -> {None, {"X", "Y"}},
TableSpacing -> {1, 4}, TableAlignments -> Right]];

And the results :

X Y
-12 891628
-11 528522.
-10 297984
-9 158106.
-8 77812
-7 34804.5
-6 13729.6

see the Y's corresponding to X=-11 and -9, doesn't have the decimal part as declared :(
How i do make it right ?
Thanks, very much
 
Physics news on Phys.org
Use NumberForm[].

In[18]:= NewMat=Map[NumberForm[#,{8,2}]&,Mat,{-1}];

In[19]:= FullForm[NewMat]

Out[19]//FullForm= List[
List[NumberForm[-12,List[8,2]],NumberForm[891628,List[8,2]]],
List[NumberForm[-11,List[8,2]],NumberForm[528522.1`,List[8,2]]],
List[NumberForm[-10,List[8,2]],NumberForm[297984,List[8,2]]],
List[NumberForm[-9,List[8,2]],NumberForm[158106.1`,List[8,2]]],
List[NumberForm[-8,List[8,2]],NumberForm[77812,List[8,2]]],
List[NumberForm[-7,List[8,2]],NumberForm[34804.5`,List[8,2]]],
List[NumberForm[-6,List[8,2]],NumberForm[13729.6`,List[8,2]]]]

In[20]:= Print["Table of values: "];
Print[TableForm[NewMat,TableHeadings->{None,{"X","Y"}},
TableSpacing->{1,4},TableAlignments->Right]];

From In[20]:=Table of values:

From In[20]:=
X Y
-12 891628.
-11, 528522.1
etc.
 
Thanks a lot! It worked fine...
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K