Date: May 13, 2013 9:34 AM
Author: Tarik
Subject: for loop

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