Solving Diophantine Equations in MATLAB
20 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2016 年 8 月 15 日
編集済み: MathWorks Support Team
2022 年 10 月 8 日
How do I solve Diophantine Equations in MATLAB?
採用された回答
MathWorks Support Team
2022 年 10 月 8 日
編集済み: MathWorks Support Team
2022 年 10 月 8 日
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
For details on “solve”, see: https://www.mathworks.com/help/symbolic/sym.solve.html
For more information on assumptions, see: https://www.mathworks.com/help/symbolic/assumptions-for-symbolic-objects.html
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Assumptions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!