I want to solve a linear equation of the form ax+by= gcd(a,b)
On paper, I would solve it using the Euclidean algorithm steps.
Is there a way to solve this using GNU Octave?
I want to solve a linear equation of the form ax+by= gcd(a,b)
On paper, I would solve it using the Euclidean algorithm steps.
Is there a way to solve this using GNU Octave?
A bit of google gives https://octave.sourceforge.io/octave/function/gcd.html
: g = gcd (a1, a2, …)
: [g, v1, …] = gcd (a1, a2, …)
Compute the greatest common divisor of a1, a2, ….
If more than one argument is given then all arguments must be the same size or scalar. In this case the greatest common divisor is calculated for each element individually. All elements must be ordinary or Gaussian (complex) integers. Note that for Gaussian integers, the gcd is only unique up to a phase factor (multiplication by 1, -1, i, or -i), so an arbitrary greatest common divisor among the four possible is returned.
Optional return arguments v1, …, contain integer vectors such that,
g = v1 .* a1 + v2 .* a2 + … Example code:
gcd ([15, 9], [20, 18]) ⇒ 5 9
So what you do is
[g, x, y] = gcd(a, b)
Also, you are not prohibited from writing the code for extended Euclidean algorithm.