www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SolutiontoDiophantineEquationExample.m
%% Solution to Diophantine Equation % Solve the Diophantine equation, $30x + 56y = 8$ for $x$ and $y$. %% % Find the greatest common divisor and a pair of Bézout coefficients % for |30| and |56|. [g,u,v] = gcd(30,56) %% % |u| and |v| satisfy the Bézout's identity, |(30*u) + (56*v) = g|. %% % Rewrite Bézout's identity so that it looks more like the original % equation. Do this by multiplying by |4|. Use |==| to verify that both % sides of the equation are equal. (30*u*4) + (56*v*4) == g*4 %% % Calculate the values of $x$ and $y$ that solve the problem. x = u*4 y = v*4