How to apply a function on a number which is in 'sym' format?

1 vue (au cours des 30 derniers jours)
Ammy
Ammy le 21 Fév 2022
p = sym('2')^100 - 15;
results = p_inverse(p-1, p);
where the function p_inverse is defined as;
function ia = p_inverse(a, p)
[~,ia] = gcd(a,p);
end
How can I find p_inverse for such p as defined above?

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Fév 2022
p = sym('2')^100 - 15;
results = p_inverse(p-1, p)
results = 
1267650600228229401496703205360
mod(results * (p-1),p)
ans = 
1
function inv = p_inverse(a, p)
[~, ia] = gcd(a,p);
inv = mod(ia, p);
end

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by