How to break a number down into 4 squares

2 ビュー (過去 30 日間)
John Smith
John Smith 2016 年 11 月 30 日
コメント済み: John D'Errico 2016 年 11 月 30 日
Hey, I'm pretty new to MATLAB, and am thinking of creating a short function which would help me visualize Lagrange's 4 square theorem. I've figured out that to break down the number into 4 squares, if it is for example n = x^2+y^2+z^2+r^2, then i should specify each number, such that 0=<x=<n/2, then 0<=y<=x/2 and so forth (the mathematical background behind it). Any tips on how I can get this into matlab (just looking for some tips so I know where to start from).
Immense thanks to anyone who helps!
  1 件のコメント
Alexandra Harkai
Alexandra Harkai 2016 年 11 月 30 日
This is not a MATLAB question, by the looks of it, unless you already have a particular algorithm in mind that you are looking to implement.

サインインしてコメントする。

回答 (2 件)

Alexandra Harkai
Alexandra Harkai 2016 年 11 月 30 日
Such a breakdown (each output number should be at most the half of the previous one) does not always exist, take 23 for example:
23 = 3^2 + 3^2 + 2^2 + 1^1
So the algorithm you want would not be able to return the 4 output numbers the way you specified.
Let me reiterate that I think this is not even a MATLAB question. The real question is what you want the algorithm to do exactly, which has nothing to do with MATLAB.

John Smith
John Smith 2016 年 11 月 30 日
Indeed, I have made a mistake in my assumptions, but nevertheless the framework Ganesh has given me is a good starting point. As soon as I edit my algorithm, I should be able to figure out the MATLAB part now.
Thanks for the help!

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by