How to half the value of a constant inside an iteration?

2 ビュー (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2019 年 2 月 12 日
編集済み: Kevin Phung 2019 年 2 月 12 日
I have an iteration loop. Inside the loop, I have a constant gamma. I want its starting value to be 10e-8. I want to half its value on every iteration (10e-4 on second iteration). How to do it?
maxiter = 100;
while iter< maxiter
gamma = 1Oe-8
f = gamma * p;
end
  4 件のコメント
Ahmad Hasnain
Ahmad Hasnain 2019 年 2 月 12 日
p is a number. It is a result of multiplication of two vectors. After multiplying gamma and p. I have to plot values of f and p at every iteration. I will plot the values of f and gamma then I will decide which value of gamma I will use. At the end, I have to use just one value of gamma but first I want to plot the values to find the suitable one.
maxiter = 100;
while iter< maxiter
p = alpha(:)'*(1-alpha(:));
gamma = 1Oe-8
f = gamma * p;
end
Ahmad Hasnain
Ahmad Hasnain 2019 年 2 月 12 日
Sorry for not explaining it better. I want to do it like this:
10e-8 , 10e-4, 10e-2, 10e-1, 10e-0.5

サインインしてコメントする。

採用された回答

Kevin Phung
Kevin Phung 2019 年 2 月 12 日
編集済み: Kevin Phung 2019 年 2 月 12 日
maxiter = 100;
iter = 1;
x = 1:1:99;
n = 8*(1/2).^x; % n = 8 , 4, 2, 0.5,...
while iter< maxiter
gamma = 10 * 10^(-n(iter)); % 10e-8, 10e-4,...
f = gamma * p;
iter = iter + 1;
end
edit: changed x to 1:1:99 instead of 1:1:100

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by