# sqrt(2) 100 places and more

22 views (last 30 days)
Aldin on 15 Dec 2011
How to disply sqrt(2) to 100 decimal places in MATLAB or more than 100 decimal places???How to limit my precision
Aldin on 15 Dec 2011
Thanks to all for helping...

Aldin on 15 Dec 2011
phi = sym('sqrt(2)'); vpa(phi,100)
Sean de Wolski on 15 Dec 2011
Good job!

the cyclist on 15 Dec 2011
I am not sure, but I think this suite of functions does what you want:
Aldin on 15 Dec 2011
Thank you a lot. This is what i need:
http://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
It will be enough for me when i get just 100 decimal
Or if you know if it is possible in JAVA you can tell me.

Sean de Wolski on 15 Dec 2011
If you have the symbolic math toolbox, you can try this:
syms x
vpa(subs(sqrt(x),2),100)
%copying first two lines from nasa file
nasa = '1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735013846230912297024924836055850737212644121497099935831';
syms x;
mlvpa = vpa(subs(sqrt(x),2),length(nasa)-1); %subtract 1 to account for decimal
isequal(char(mlvpa),nasa)
ans = 1
woo!
Aldin on 15 Dec 2011
Here is the result for R2009b
phi = sym('sqrt(2)'); vpa(phi,100)
Can you say me the result in JAVA

Laura Proctor on 15 Dec 2011
format long
will show 15 digits.
fprintf(1,'%.100f\n',sqrt(2))
will show 100 digits. However, that precision is not stored in sqrt(2) - you can see that most of the digits are zero.
By default, numbers are stored as double in MATLAB. In order to understand what that means, I'm linking the following page:
Aldin on 15 Dec 2011
Laura,
Thank you for your answer. I know "double" from JAVA. But i need 100 precesion not 16. See this: http://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
Or if you know if it is possible in JAVA you can tell me.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!