For loop outputs into Row Vector
显示 更早的评论
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
回答(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 个评论
John D'Errico
2020-12-13
That cannot possibly work, because s is not correctly represented as a double.
John D'Errico
2020-12-13
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]
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!