Path: news.mathworks.com!not-for-mail
From: "Tarik " <tarikak@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: for loop
Date: Mon, 13 May 2013 13:34:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <kmqq4f$dpf$1@newscl01ah.mathworks.com>
Reply-To: "Tarik " <tarikak@gmail.com>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1368452047 14127 172.30.248.48 (13 May 2013 13:34:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 13 May 2013 13:34:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4304580
Xref: news.mathworks.com comp.soft-sys.matlab:795439

hi...

it's really hard for me to explain what i want to calculate... but here is a part of my codes... when I write "n(9)"

ans =

     0     0     3
     0     3     0
     3     0     0

and if I cahange l as l=1:sqrt(ni) (it starts from 1)... now

ans =

     1     2     2
     2     1     2
     2     2     1

my problem is that both ans are in my expectation... I mean, for loop doesn't work well here... it looks that it stops after a solution... but why???

   for l=0:sqrt(ni)
         x=l;                    
         
       y=real(fix(sqrt(ni-x^2)));       
       if fix(y)==y           
       z=real(fix(sqrt(ni-x^2-y^2)));       
       if fix(z)==z           
       if ni==x^2+y^2+z^2;          
       n=[x,y,z];            
       
       result=unique(perms(n),'rows');       
             return      
              end
              end
              end
      end