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!