I want to change value of a variable after every 10 iterations
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Walter Roberson
2019-2-15
for iter = 1:100
k = 1 + floor((iter-1)/10)
2 个评论
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 Center 和 File Exchange 中查找有关 Gamma Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!