p=sym('5744092954902128823202697');
randi([2,p-2])
So I've defined p and tried to compute randi([2,p-2]), Matlab returns: 'Size and range inputs must be numeric.'.
I know it's something to do with the symbolic variable but I do not know why this is happening, nor the solution. Is there a way to do this without converting p to numeric because I don't want to lose precision
THANK YOU!

 Réponse acceptée

Walter Roberson
Walter Roberson le 11 Déc 2019
Modifié(e) : Walter Roberson le 11 Déc 2019

1 vote

Rsymproc = feval(symengine, 'random', p-3);
Rsym = @() feval(symengine, Rsymproc) + 1;
Now each call to Rsym() will return one random number in the range [2, p-2]
Note: the internal procedure generated for this does not accept array sizes, so to generate multiple values, call Rsym multiple times.

3 commentaires

Yuechuan Chen
Yuechuan Chen le 12 Déc 2019
Modifié(e) : Yuechuan Chen le 12 Déc 2019
So using the information you've provided I did
Rsymproc = feval(symengine, 'random', p-3);
Rsym = @() feval(symengine, Rsymproc) + 2;
feval(symengine, Rsym)
which looks legit, is this right?
Yuechuan Chen
Yuechuan Chen le 12 Déc 2019
Modifié(e) : Yuechuan Chen le 12 Déc 2019
So my interpretation is that Rsymproc generates a random integer in the range [0,p-4], and Rym increases the minima&maxima by 2 so it becomes [2,p-2], and feval just outputs the number generated.
I tried this with p=7 and q=3 and it seemed correct.
You do not need to
feval(symengine, Rsym)
You can just
Rsym()
You are correct in your intepretation of how the functions work.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by