I want to change value of a variable after every 10 iterations

조회 수: 3 (최근 30일)
Ahmad Hasnain
Ahmad Hasnain 2019년 2월 15일
댓글: Walter Roberson 2019년 2월 15일
I am doing 100 iterations. I have a variable gamma that multiplies with a vector a. I want to update the value of gamma after every 10 iterations. I wrote a For loop but I can't seem to figure out how to update it after every ten iterations.
iter = 0;
while iter<100
iter = iter + 1;
a = vector;
constt = sqrt(10);
gamma = 10^-8;
for k = 1:10
f(?) = gamma(?) * a'*(1-a);
gamma(k+1) = constt * gamma(k);
end
end
I need to calculate f with different values of gamma after every 10 iterations. I am not sure what will be the indexing for f and gamma in the equation.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 2월 15일
for iter = 1:100
k = 1 + floor((iter-1)/10)
  댓글 수: 2
Ahmad Hasnain
Ahmad Hasnain 2019년 2월 15일
I use a while loop for iterations. So I do not need a FOR loop for changing values of gamma?
Walter Roberson
Walter Roberson 2019년 2월 15일
you are using aa fixed number of iterations so for is clearer . But whatever , use while if you like . The calculation I show is for after iter has been incremented.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Gamma Functions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by