Solves the diophantine (Bezout) equation p1*x1 + p2*x2 = b
[x1x2, err] = diophant(p1p2, b)
Vectors of two numbers or polynomials p1p2 = [p1 p2]
and x1x2 = [x1 x2]
,
with the same size and type (integers, numbers, polynomials).
When there is no solution, x1x2 = []
single number or polynomial
Single real number: error flag:
0 | No error. |
---|---|
-%inf | There is an infinite number of solutions. |
%nan | p1==0 , p2==0 , while
b <> 0 : No solution. |
> 0 | There is no solution.
err = ||coeff(b - int(b/g)*g)|| / ||coef(b)||
where g = gcd(p1,p2) . |
diophant
solves the bezout equation p1*x1 + p2*x2 = b
for polynomials, encoded integers, or numbers.
If input arguments are encoded integers, only integer solutions are searched.
If input arguments are decimal numbers or constant polynomials, there is always an infinite number of solutions.
When there is an infinite number of solutions, only one [x1 x2] solution is returned.
[X, e] = diophant(int8([4, 7]), 5) // int8([10 -5]) [X, e] = diophant(int16([1234 5321]), 543); // int16([30533 -2339]) sum(X .* [1234 5321]) s = %s; p = (1+s)*(s-1) + (1-s^2)*s; [X, e] = diophant([1+s ; 1-s^2], -1+s+s^2-s^3); // [-1+2*s-s^2 ; 0] sum(X .* [1+s ; 1-s^2]) | ![]() | ![]() |
No solution exists:
s = %s; [X, e] = diophant([0, 0], 1) [X, e] = diophant([s^3, s^2], s) [X, e] = diophant([1+s ; 1-s^2], 1-s+s^2) [X, e] = diophant(int8([2 0]), int8(1)) // No integer solution | ![]() | ![]() |
An infinite number of solutions exists:
Version | Description |
6.1.0 |
|