f(x) having fixed significant digits in Table

f(x) having fixed significant digits in Table



Define function f


Clear[f, x];
f[x_] := 2^x;



N[ f[arg], #sig. digits]


data = Table[
N[Pi, n],
N[ f[N[Pi, n]], 10 ]
, n, 1, 8
];



Text gridding...


Text@Grid[Prepend[data, "x", "f(x)"],
Alignment -> Left,
Dividers -> Center, 2 -> True
]



beginarrayl
textx & textf(x) \
hline
3. & 0. \
3.1 & 9. \
3.14 & 8.8 \
3.142 & 8.82 \
3.1416 & 8.825 \
3.14159 & 8.8250 \
3.141593 & 8.82498 \
3.1415927 & 8.824978 \
endarray



How do I show the following instead?



beginarrayl
textx & textf(x) \
hline
3. & 8.000000 \
3.1 & 8.574188 \
3.14 & 8.815241 \
3.142 & 8.821353 \
3.1416 & 8.824411 \
3.14159 & 8.824962 \
3.141593 & 8.824974 \
3.1415927 & 8.824978 \
endarray




2 Answers
2



Using arbitrary precision arithmetic produces the 1st result you show because Mathematica normally does not show digits with no precision since they are just noise. However, if you are trying to show how having better and better rational approximations to π improves the approximation of $2^pi$, I suggest the following approach.


data =
With[x = π, n = 8,
Table[
With[u = Round[x, 10^-i], u, Round[f[u], 10^-i]] // N,
i, 0, n]];
TableForm[Map[NumberForm[#, 10, 8] &, data, 2],
TableHeadings -> None, x, f[x]]



table



It might take some additional formatting to get exactly what you're after, but this is a start. I acknowledge some things may be able to be made simpler.


Clear[f, x];
f[x_] := 2^x;
data = N@Table[
Table[10^(-j + 1), j, 1, i].RealDigits[N@Pi, 10, i][[1]], i,
8] /. x_?NumericQ :> NumberForm[x, 8], f[x];

Text@Grid[Prepend[data, "x", "f(x)"], Alignment -> Left,
Dividers -> Center, 2 -> True]



enter image description here



Thanks for contributing an answer to Mathematica Stack Exchange!



But avoid



Use MathJax to format equations. MathJax reference.



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế