Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tarik

Posts: 6
Registered: 5/13/13
for loop
Posted: May 13, 2013 9:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
Read for loop
Tarik
5/13/13
Read Re: for loop
Tarik
5/13/13
Read Re: for loop
dpb
5/13/13
Read Re: for loop
dpb
5/13/13
Read Re: for loop
Tarik

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.