Octave while/for statement -- what's wrong in a code? -
this octave code
k= 1:10 while ( p < 1 ) ceil(log2(k)) + 1/(1-(1-p)^k) %function p = p + sens; k endwhile; endfor k and here output:
ans = 10.000 k = 1 ans = 5.0000 k = 1 ans = 3.3333 k = 1 ans = 2.5000 k = 1 ans = 2 k = 1 ans = 1.6667 k = 1 ans = 1.4286 k = 1 ans = 1.2500 k = 1 ans = 1.1111 k = 1 ans = 1 k = 1 k = 10 so, can see -- in inner while statement value of k fixed 1. supposed vary value between 1 , 10. why not working? have no idea why inner while statement proceed once.
answer: there should p= initial_value after for k=...
[even if find answer question yourself, should put in answer , accept it, question "officially" solved. have commented don't have enough reputation here]
answer: there should p= initial_value after for k=... is, this:
for k= 1:10 p=somevalue; while ( p < 1 ) ...
Comments
Post a Comment