For loop outputs into Row Vector
Show older comments
I need help to put the outputs of my for loop into a row vector
s =1473687476902629535821802641425569585752815039365228611687
r = 6
a=7
for i=[0:r]
powermod(a,s*2^i,n)
end
Answers (2)
s =1473687476902629535821802641425569585752815039365228611687
r = 6 ;
a = 7 ;
r = 0:r ;
iwant = zeros(length(r),1) ;
for i=1:length(r)
iwant(i) = powermod(a,s*2^r(i),n)
end
1 Comment
John D'Errico
on 13 Dec 2020
That cannot possibly work, because s is not correctly represented as a double.
John D'Errico
on 13 Dec 2020
You don't say the value of n there. So I'll choose some value.
Next, you need to store s in a form where it will be represneted exactly. You cannot perform huge precision computations using doubles.
s = sym('1473687476902629535821802641425569585752815039365228611687');
r = 6;
a = 7;
n = 17; % my example, so my favorite number
result = zeros(1,r+1,'sym');
for i=[0:r]
result(i+1) = powermod(a,s*2^i,n);
end
result
result =
[12, 8, 13, 16, 1, 1, 1]
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!