How to increase precision in this case?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
John D'Errico
on 19 Oct 2022
Edited: John D'Errico
on 19 Oct 2022
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 Comments
John D'Errico
on 19 Oct 2022
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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!