フィルターのクリア

How to generate series by percentage difference using loop?

1 回表示 (過去 30 日間)
Triveni
Triveni 2022 年 6 月 22 日
コメント済み: Triveni 2022 年 6 月 24 日
I have a value
A(1) = 60;
A(2) = A(1) *0.99;
A(3) = A(2) *0.99;
A(4) = A(3) *0.99;
A(5) = A(4) *0.99;
A(6) = A(5) *0.98; % Values changing after 5 iteration
.
.
.
A(11) = A(10) *0.97; % Values changing after 5 iteration
.
.
.
.till the differences reached to 0.01.
Please help me.

採用された回答

KSSV
KSSV 2022 年 6 月 22 日
編集済み: KSSV 2022 年 6 月 22 日
A = zeros([],1) ;
A(1) = 60 ;
dA = 1 ;
i = 1 ;
while dA > 0.01
i = i+1 ;
A(i) = A(i-1)*0.99 ;
dA = abs(A(i)-A(i-1)) ;
end
  4 件のコメント
Triveni
Triveni 2022 年 6 月 23 日
Value of .99 is not changing after 5th iteration. Means A(6) = A(5) *0.98; please correct.
Triveni
Triveni 2022 年 6 月 24 日
%----------------------------------------
PP = 28;
sdf = 0.995;
%----------------------------------------
%Generate Series
A = zeros([],1) ;
A(1) = PP;
dA = 1 ;
i = 1 ;
while dA > 0.0001
i = i+1 ;
if length(A)>4 && rem(length(A),5)==0
sdf = sdf-.01;
A(i) = A(i-1)*sdf ;
else
A(i) = A(i-1)*sdf ;
end
dA = abs(A(i)-A(i-1)) ;
end
A = round(unique(A'),2);
A = A(fliplr(1:end),:);
N = 0.05; % Round value
B = unique(nonzeros(round(A/N)*N));
A = B(fliplr(1:end),:);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by