sqrt(2) 100 places and more

How to disply sqrt(2) to 100 decimal places in MATLAB or more than 100 decimal places???How to limit my precision

 채택된 답변

Aldin
Aldin 2011년 12월 15일

3 개 추천

Here is the answer:
phi = sym('sqrt(2)'); vpa(phi,100)

추가 답변 (3개)

the cyclist
the cyclist 2011년 12월 15일

1 개 추천

I am not sure, but I think this suite of functions does what you want:

댓글 수: 1

Aldin
Aldin 2011년 12월 15일
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
Sean de Wolski 2011년 12월 15일

1 개 추천

If you have the symbolic math toolbox, you can try this:
syms x
vpa(subs(sqrt(x),2),100)
More per comments:
%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!

댓글 수: 17

Aldin
Aldin 2011년 12월 15일
Sean,
Thanks a lot. I need it for Uni. It is my homework.(numerical mathematics and computing)
See this: http://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
I have to write the code in Java or Matlab. I don't know how to display more than 16 digits in JAVA or MATLAB.
Aldin
Aldin 2011년 12월 15일
Here is the result of your code:
1.4142135623730951454746218587388284504413604736328125
But is not 100 digits.
Sean de Wolski
Sean de Wolski 2011년 12월 15일
That is not the result of either snippet of code I provided.
Aldin
Aldin 2011년 12월 15일
ans = 0
Sean de Wolski
Sean de Wolski 2011년 12월 15일
What are you running (copy and paste the code)? What version? Ans what does
which -all vpa
return?
Aldin
Aldin 2011년 12월 15일
How does they can find square root of two by so many digits???
Aldin
Aldin 2011년 12월 15일
cop and pate in M-file your code:
nas = '------';
syms x;
...... etc...
and the answer is ans = 0
Aldin
Aldin 2011년 12월 15일
MATLAB 7.9.0 (R2009b)
Aldin
Aldin 2011년 12월 15일
When i type following:
x = 2;
vpa(subs(sqrt(x),2),100)
Result is:
1.4142135623730951454746218587388284504413604736328125
Sean de Wolski
Sean de Wolski 2011년 12월 15일
copy and paste the whole code!!!!! I can't figure out what ....etc.,... means. If you have the string, '------' set to nasa, then of course it's not going to work, the right answere is not six hyphens. If you _literally_ copy and paste what I have above, it should and will run, assuming you have the SMT.
Aldin
Aldin 2011년 12월 15일
i swear the answer is ans = 0, Can i send you email with picture where can you see what i type in my workspace in matlab than you will se the answer is 0
Aldin
Aldin 2011년 12월 15일
Yes you dis, Why?
Sean de Wolski
Sean de Wolski 2011년 12월 15일
Take a screen shot and post it to a free webhosting site, that way everyone can see it.
Aldin
Aldin 2011년 12월 15일
Ok wait a minute.
Aldin
Aldin 2011년 12월 15일
Here is the link:
http://www.mediafire.com/?iyz0u7bjzvqratj
Sean de Wolski
Sean de Wolski 2011년 12월 15일
After installing R2009b, I'm able to replicate the behavior you're seeing on it. My syntax above works on R2011b.
Aldin
Aldin 2011년 12월 15일
Here is the result for R2009b
phi = sym('sqrt(2)'); vpa(phi,100)
Can you say me the result in JAVA

댓글을 달려면 로그인하십시오.

Laura Proctor
Laura Proctor 2011년 12월 15일

0 개 추천

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:

댓글 수: 1

Aldin
Aldin 2011년 12월 15일
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.

댓글을 달려면 로그인하십시오.

질문:

2011년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by