Message Boards Message Boards

0
|
1644 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

If inside For - Part not working for higher iterations

Posted 11 years ago

Bonjour,

 sup = s[[1]];
For[j = 2, j <= n, j++,
  If [s[[j]] >= sup, sup = s[[j]], sup = sup];
  ];

i don't know why this function If doesn't give me the high number of list s ? it give me always the number s[[1]]. please if there any response for this problem.

thank you

POSTED BY: ayour aziz
Posted 11 years ago

x

In[1]:= s = RandomReal[{0, 1}, 6]

Out[1]= {0.0983261, 0.814716, 0.152864, 0.588498, 0.39265, 0.60135}

In[2]:= sup = s[[1]];
For[j = 2, j <= n, j++, If[s[[j]] >= sup, sup = s[[j]]];];

In[4]:= sup

Out[4]= 0.0983261

In[5]:= sup = s[[1]];
n = Length[s];
For[j = 2, j <= n, j++, If[s[[j]] >= sup, sup = s[[j]]];];

In[8]:= sup

Out[8]= 0.814716
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract