see, i have this error in my code saying: ??? Attempted to access x(0); index must be a positive integer or logical. Error in ==> abc at 14 x(i)=mod(g^x(i-1), p);
Show older comments
clear all; close all; clc;
p = input('Introduceti numarul prim p= ');
g = input('Introduceti numarul prim g= ');
Nr=p-1;
x=zeros(1, Nr);
for i=1:Nr
x(i)=mod(g^x(i-1), p);
end;
disp('Rezultatul este: ');
disp(x);
1 Comment
Walter Roberson
on 16 Jul 2015
Accepted Answer
More Answers (1)
Walter Roberson
on 16 Jul 2015
1 vote
You have x(i)=mod(g^x(i-1), p); . When "i" is 1, that is mod(g^x(1-1),p) which is mod(g^x(0),p) . However there is no element #0 of a vector.
You need to think more about your initial conditions, of what is to happen on the very first iteration.
2 Comments
Andreea Alexandra
on 16 Jul 2015
Walter Roberson
on 16 Jul 2015
I suspect what you want is
x(1) = 1;
for i=2:Nr
x(i)=mod(g^x(i-1), p);
end
Categories
Find more on Matrix Indexing 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!