Solving Diophantine Equations in MATLAB

27 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 15 de Ag. de 2016
Editada: MathWorks Support Team el 8 de Oct. de 2022
How do I solve Diophantine Equations in MATLAB?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 8 de Oct. de 2022
Editada: MathWorks Support Team el 8 de Oct. de 2022
Use the “solve” function. Before using “solve”, assume that the variables in the Diophantine equation are integers to ensure “solve” returns integer solutions. For example, solve the linear Diophantine equation 1027*x + 712*y = 1;
For MATLAB R2015a and later:
syms x y integer % assume ‘x’ and ‘y’ are integers
eqn = 1027*x + 712*y == 1; % declare the equation
[xSol, ySol] = solve(eqn,[x y]) % solve for ‘x’ and ‘y’
xSol =
-165
ySol =
238
For MATLAB R2014b or before:
syms x y
assume([x y], 'integer') % assume ‘x’ and ‘y’ are integers
eqn = 1027*x + 712*y == 1; % declare the equation
[xSol, ySol] = solve(eqn,[x y]) % solve for ‘x’ and ‘y’
xSol =
-165
ySol =
238

Más respuestas (0)

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by