matlab中的GCD函数
我正在寻找一种方法来用另一种语言实现 matlab 中使用的“gcd”函数,但我真的无法理解它的工作方式。
它在 http://www.mathworks.com/access 中说/helpdesk/help/techdoc/ref/gcd.html 指出:
“[G,C,D] = gcd(A,B) 返回最大公约数数组 G 以及数组 C 和 D,其中满足方程:A(i).*C(i) + B(i).*D(i) = G(i)。
但它没有说明如何计算 C 和 D。
如果有人对这个主题有更清晰的想法,我将不胜感激! 谢谢:)
i am looking for a way to implement the "gcd" function used in matlab in another language but i really cant understand the way it functions.
it says in http://www.mathworks.com/access/helpdesk/help/techdoc/ref/gcd.html that:
"[G,C,D] = gcd(A,B) returns both the greatest common divisor array G, and the arrays C and D, which satisfy the equation: A(i).*C(i) + B(i).*D(i) = G(i)."
but it says nothing about how it calculates C and D.
i would be grateful if someone has a clearer idea about this subject!
thanks:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
扩展欧几里得算法。
(“第 4.5.2 节算法 X”可以在 http://www.fitc.unc.edu.ar/javadev/math/previous/algorithms.html。)
The extended Euclidean algorithm.
("Section 4.5.2 Algorithm X" being this can be shown in http://www.fitc.unc.edu.ar/javadev/math/previous/algorithms.html.)
Matlab 文档参考
Knuth, Donald, 计算机编程的艺术, 第 1 卷。 2、Addison-Wesley:Reading MA,1973。第 4.5.2 节,算法 X。
我没有冒昧地为您解释这一点,但它就在那里。
The Matlab documentation refers to
Knuth, Donald, The Art of Computer Programming, Vol. 2, Addison-Wesley: Reading MA, 1973. Section 4.5.2, Algorithm X.
I don't have the temerity to paraphrase that for you, but it is all there.
即可查看源代码
只需在编辑器中输入打开该函数 。然后你可以逐行查看该函数。
结合其他两篇文章中的参考资料,这应该会给您答案。
Just have a look at the source by typing
which opens the function in the editor. Then you can look through the function line by line.
Together with the references in the other two posts, this should get you the answer.
它将使用此链接中关于扩展欧几里得算法的基本方案之一。
It would use one of the basic schemes found in this link on The extended Euclidean algorithm.