Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: for loop
Replies: 4   Last Post: May 13, 2013 4:37 PM

 Messages: [ Previous | Next ]
 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(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

Date Subject Author
5/13/13 Tarik
5/13/13 Tarik
5/13/13 dpb
5/13/13 dpb
5/13/13 Tarik