Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Tarik
Posts:
6
Registered:
5/13/13


for loop
Posted:
May 13, 2013 9:34 AM


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(nix^2))); if fix(y)==y z=real(fix(sqrt(nix^2y^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



