Integer check with a symbolic variable
Ältere Kommentare anzeigen
So I have:
s=sym('10517669');
p=nextprime(8*(S^4));
if float((p-1)/2)==(p-1)/2
...
end
I know float only works for single&double-precision, but p is so large I have to use the symbolic toolbox because it don't want to lose precision.
How could I resolve this?
THANKS
2 Kommentare
Fangjun Jiang
am 12 Dez. 2019
p is accurately represented using sym object in your code. You know p is an integer from theory. What do you try to do? double(p) or single(p) can't represent p without precision loss.
Yuechuan Chen
am 12 Dez. 2019
Bearbeitet: Yuechuan Chen
am 12 Dez. 2019
Akzeptierte Antwort
Weitere Antworten (1)
Fangjun Jiang
am 13 Dez. 2019
1 Stimme
If you want to check whether (p-1)/2 is an integer, then check whether p is an odd number. But since p is a prime number, it seems p is always odd except that p==2.
1 Kommentar
Yuechuan Chen
am 13 Dez. 2019
Kategorien
Mehr zu Calculus finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!