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개)

KSSV
KSSV 2020년 12월 13일
편집: KSSV 2020년 12월 13일

0 개 추천

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
John D'Errico 2020년 12월 13일
That cannot possibly work, because s is not correctly represented as a double.

댓글을 달려면 로그인하십시오.

John D'Errico
John D'Errico 2020년 12월 13일

0 개 추천

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에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2020년 12월 13일

답변:

2020년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by