import java.math.*;
>> p=BigInteger('11');
>> m=BigInteger('2');
>> [A,B]=m.gcd(p);
Error using java.math.BigInteger/gcd
Java methods cannot be called with multiple output arguments
How to resolve this issue? I need both A and B.
Thanking in anticipation

댓글 수: 7

Rik
Rik 2022년 3월 2일
What is the second output? There might be a way to compute it separately.
Ammy
Ammy 2022년 3월 2일
편집: Ammy 2022년 3월 2일
[A,B]=gcd(2,11)
A=1; B=-5;
Ammy
Ammy 2022년 3월 2일
It works when the integers are not in the above format, but showing error with the above format.
Rik
Rik 2022년 3월 2일
Ok, I admit I wasn't clear enough with my question: what is the second output supposed to be in a more general sense? There is only 1 greatest common denominator, so what second value could you extract from it?
I have no experience interfacing with Java (except for copy-paste examples), so I can only help you to try to find a method to calculate the second output another way.
AndresVar
AndresVar 2022년 3월 2일
@Ammy gcd usually just gives 1 output. The matlab function with more than 1 output is returning the Bezout coefficients. Which you can calculate yourself.
You can see Matlab calculates it: edit gcd
Or you can find the algorithm online
Ammy
Ammy 2022년 3월 2일
@Rik Thank you ver much!
I want to extract the following
[A,B] = gcd(m,p);
if A =1 then
a = mod(B,p)
otherwise a=0
I want to find a which depends on both A and B
Ammy
Ammy 2022년 3월 2일
@AndresVar, thank you very much but I want to deal with both the outputs.

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

 채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 2일

1 개 추천

import java.math.*;
p = BigInteger('11');
m = BigInteger('2');
A = m.gcd(p)
A = 1
B = m.modInverse(p)
B = 6
m.multiply(B).mod(p)
ans = 1

댓글 수: 3

Ammy
Ammy 2022년 3월 2일
편집: Rik 2022년 3월 2일
@Walter Roberson Thank you very much, Yes I had tried this, but can you please help me is there any way to deal it in a function.
If I have a function inverse.m
import java.math.*;
p = BigInteger('11');
m = BigInteger('2');
ans= m.inverse(p);
where
function a = inverse(b, p)
b = mod(b, p);
[A,B] = gcd(b, p);
if A==1
a = mod(B,p);
else
a = 0;
end
end
import java.math.*;
p = BigInteger('11');
m = BigInteger('2');
a = inverse(m, p)
a = 6
%cross-check
cross_check = m.multiply(a).mod(p)
cross_check = 1
function a = inverse(b, p)
import java.math.*;
A = b.gcd(p);
if A == BigInteger('1')
a = b.modInverse(p);
else
a = BigInteger('0');
end
end
Ammy
Ammy 2022년 3월 2일
Thank you very much!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2022년 3월 2일

댓글:

2022년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by