Array element containing infinity
이전 댓글 표시
Hi. I have a problem in array indexing containing infinity.
I have to compute the function f(a)=1-1/a mod 13 . It takes values from [infinity 0,1,2 ...12] and out put should be [1,inf,0,7,5,4,6,3,12,9,11,10,8 and 2]
I have tried to code it but it gives error at infinity.
Y_trans=[];
p=[];
n=13;
P_2=[];
y_axis=[];
for i=1:13
if modInv(i,n)==0
P_2(i)=Inf
else
P_2(i)=modInv(i,n);
[Y_trans(i)]= mod(1-P_2(i),n);
end
end
댓글 수: 6
madhan ravi
2020년 11월 17일
Your question and function seems not the same to me atleast , 1 - inf is -inf why are you saying inf?
lilly lord
2020년 11월 17일
Adam Danz
2020년 11월 17일
The expression "p mod q" in matlab is mod(p,q) but it's not clear what p should be in your formula,
f(a)=1-1/a mod 13
The mod operator is typically give then same precedence as multiplication and division so one interpretation is
f(a) = 1-mod(1/a, 13)
but other interpretations are
f(a) = mod(1-1/a, 13)
f(a) = 1-1/mod(a, 13)
None of these interpretation are in your code, though. You're using the following which ignore the reciprocal "1/" unles that's already done in modInv (this is why it's helpful to define your variables so we understand what they are).
f(a) = mod(1-a, 13)
Nevertheless, an inf value shouldn't cause an error in the mod function so please share the entire error message and provide us with your inputs.
lilly lord
2020년 11월 17일
lilly lord
2020년 11월 17일
Adam Danz
2020년 11월 17일
" please share the entire error message", all of it, and let us know which line is throwing the error.
The only indices I see are i and n and both are positive integers.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!