sumsqint
版本 1.1.0.0 (4.3 KB) 作者:
Ben Petschel
Finds all distinct ways of writing a number as the sum of squares, i.e. solve x^2+y^2=n for 0<=x<=y.
Example:
sumsqint(1) % returns [0,1]
sumsqint(65) % returns [1,8;4,7]
sumsqint can work with large numbers if they are factored, e.g. solve x^2+y^2=(25e6)^2:
sumsqint(repmat(factor(25e6),1,2)) % returns 9x2 array
sumsqint works with variable precision integers if you have John D'Errico's Variable Precision Integer toolbox (20 July 2009 update) - see links below.
sumsqint(vpi(5)^100) % returns 51x2 vpi array
sumsqint(vpi(65)^100) % returns 5101x2 vpi array
The algorithm uses Gaussian integer factorization. See the help for more details.
引用格式
Ben Petschel (2026). sumsqint (https://ww2.mathworks.cn/matlabcentral/fileexchange/24798-sumsqint), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2009a
兼容任何版本
平台兼容性
Windows macOS Linux类别
在 Help Center 和 MATLAB Answers 中查找有关 Linear Algebra 的更多信息
