matlab中的模乘反函数

matlab中的模乘反函数,matlab,function,inverse,mod,Matlab,Function,Inverse,Mod,我有计算模乘逆的问题。 例如我有整数A=151和M=541。151国防部541。从151到541的逆模为43 如何在matlab中计算模乘逆?这可以使用和函数完成,如下所示: A = 151; M = 541; [G, C, ~] = gcd(A,M); if G==1 % The inverse of a(mod b) exists only if gcd(a,b)=1 ModMultInv = mod(C,M) else disp('Modular multiplicativ

我有计算模乘逆的问题。 例如我有整数
A=151
M=541
。151国防部541。从151到541的逆模为43 如何在matlab中计算模乘逆?

这可以使用和函数完成,如下所示:

A = 151;   M = 541;

[G, C, ~] = gcd(A,M);
if G==1  % The inverse of a(mod b) exists only if gcd(a,b)=1
    ModMultInv = mod(C,M)
else disp('Modular multiplicative inverse does not exist for these values')
end
输出:-

ModMultInv =
    43
这可以使用和功能完成,如下所示:

A = 151;   M = 541;

[G, C, ~] = gcd(A,M);
if G==1  % The inverse of a(mod b) exists only if gcd(a,b)=1
    ModMultInv = mod(C,M)
else disp('Modular multiplicative inverse does not exist for these values')
end
输出:-

ModMultInv =
    43