matlab - Storing the number of iterations of a nested loop in an array -



matlab - Storing the number of iterations of a nested loop in an array -

i relatively new matlab , quite stuck in specific problem.

i have equation trying solve using while loop. works guessing parameter e_0 , filling equation, until converges. illustration found below, initial guessing value equals 100:

clear i=1; e_0=100 e_1= e_0 + log(0.6) - log(exp(e_0)/(exp(e_0)+1)) while( < 1e10 & abs((e_1 - e_0)) > 1e-12), = + 1; e_0=e_1; e_1= e_0+log(0.6)-log(exp(e_0)/(exp(e_0)+1)) end

now exact same procedure multiple values of e_0 @ same time, e.g. 101, 102, 103 , on, , count how many more iterations take. reckon hence need set for-loop that. thought this:

clear i=1; e_0 = 100:105 e_1= e_0+log(0.6)-log(exp(e_0)/(exp(e_0)+1)) while( < 1e10 & abs((e_1 - e_0)) > 1e-12), = + 1; e_0=e_1; e_1= e_0+log(0.6)-log(exp(e_0)/(exp(e_0)+1)) end end

however, iterations different guessing values shown underneath each other, , total of 1519 iterations. how can illustration store number of iterations needed every initial guessing value underneath each other variable?

i hope clear enough... give thanks you!

how this:

i = 0; offset = 99; n = 1:6 e_0 = n + offset; e_1 = e_0+log(0.6)-log(exp(e_0)/(exp(e_0)+1)) while( < 1e10 & abs((e_1 - e_0)) > 1e-12), = + 1;

this part needs alter prevent e_0 redefined within loop:

e_1= e_1+log(0.6)-log(exp(e_1)/(exp(e_1)+1)) end iterations(n)=i; end

note: not recommended utilize i loop increment, since redefines i used in complex numbers.

matlab loops for-loop while-loop nested

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -