sqrt(2) 100 places and more
12 次查看(过去 30 天)
显示 更早的评论
采纳的回答
更多回答(3 个)
Sean de Wolski
2011-12-15
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 个评论
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.
Laura Proctor
2011-12-15
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:
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!