Why is N not giving the approximate result (removing the .)?
vectorj = Table[j, {j, 0, 0.1, 0.01}]
N[vectorj[[1]], 0]
(*out=0.*)
or
N[vectorj, 0]
or
NumberForm[vectorj[[1]], 0]
Rationalize does the job.
Why is N not giving the approximate result (removing the .)?
vectorj = Table[j, {j, 0, 0.1, 0.01}]
N[vectorj[[1]], 0]
(*out=0.*)
or
N[vectorj, 0]
or
NumberForm[vectorj[[1]], 0]
Rationalize does the job.
It's the expected result from N. The result of N is an approximate result but not an exact result.
In:
vectorj = Table[j, {j, 0, 0.1, 0.01}]
N[vectorj[[1]], 0] // Head
0 // Head
N[vectorj[[1]], 0] // Accuracy
0 // Accuracy
Out:
{0., 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1}
Real
Integer
307.653
\[Infinity]
Workaround:
In:
xs = Table[x/100, {x, 0, 10, 1}]
xs // N
Out:
{0, 1/100, 1/50, 3/100, 1/25, 1/20, 3/50, 7/100, 2/25, 9/100, 1/10}
{0., 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1}
Roundinstead.N[x,0]would give a result with zero precision (i.e. something useless). Look upPrecision. – Szabolcs Apr 28 '17 at 16:35N[vectorj, 0]? – Kuba Apr 28 '17 at 16:46