How to increase precision in this case?
1 次查看(过去 30 天)
显示 更早的评论
I have a code which finds the first 10 consecutive numbers after decimal that forms a prime number:
k = 10;
while true
a = mod(floor((pi-3)*10^k),10^10);
if isprime(a) == 1
disp(a)
break
endif
k += 1;
endwhile
And this only works for pi, I also need it to e but its not enough precision
What can i do here?
0 个评论
采纳的回答
John D'Errico
2022-10-19
编辑:John D'Errico
2022-10-19
Take it from here:
vpa(exp(sym(1)),500)
Now just process the digits.
Or I think I have something on the order of a million digits of e and pi stored in my HPF toolbox. (Might be only a half million.)
4 个评论
John D'Errico
2022-10-19
Can you extract the string of digits? I think you are fixated on the idea that you NEED to work with numbers, and there is only one possible way to extract those digits. That is completely wrong. I showed you how to extract all the digits you want. Perhaps I stopped one step short, thinking you could take it from there. So I'll add a next step.
D = char(vpa(exp(sym(1)),500))
That is not a string of numeric digits there, but a string of characters. But even so, it is all you need. Feel free to delete the decimal point even.
D(2) = []
You can even convert them into actual numeric digits if you feel the need, but you need to make some effort, and I'm sorry, but I won't do your homework, and I've already done almost all of it here.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!