sqrt(2) 100 places and more
Mostrar comentarios más antiguos
How to disply sqrt(2) to 100 decimal places in MATLAB or more than 100 decimal places???How to limit my precision
1 comentario
Aldin
el 15 de Dic. de 2011
Respuesta aceptada
Más respuestas (3)
the cyclist
el 15 de Dic. de 2011
1 voto
I am not sure, but I think this suite of functions does what you want:
1 comentario
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
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 comentarios
Aldin
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
That is not the result of either snippet of code I provided.
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
What are you running (copy and paste the code)? What version? Ans what does
which -all vpa
return?
Aldin
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
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
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
Take a screen shot and post it to a free webhosting site, that way everyone can see it.
Aldin
el 15 de Dic. de 2011
Aldin
el 15 de Dic. de 2011
Sean de Wolski
el 15 de Dic. de 2011
After installing R2009b, I'm able to replicate the behavior you're seeing on it. My syntax above works on R2011b.
Aldin
el 15 de Dic. de 2011
Laura Proctor
el 15 de Dic. de 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:
1 comentario
Aldin
el 15 de Dic. de 2011
Categorías
Más información sobre Code Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!