Good evening,
I'm working on this code which is basicaly a go through list of values with a loop and look for a variation (which I call degradation) over 5% from the refence value. That refence value will change if the "degradation" is over 5% and it will shift to the next value.
Problem :
When we go from 1 to 0.95 it's a degradation of 5% (because 5% of 1 is 0.05 and the difference is 1 - 0.05 = 0.95) so it's good.
But when we move to ref = 0.95 then the 5% degradation will be 0.0475 which is 0.95 - 0.0475 = 0.9025 and not 0.9 (logic in maths but not what I want).
What I want :
- If possible, I want the code to keep shifting ref value when the degradation is over 5% and at the same time keeping a 0.05 step.
randomlist = [1, 0.98, 0.95, 0.93, 0.9, 0.87, 0.85, 0.82, 0.8, 0.78, 0.75, 0.72, 0.7]
Degradation = 5
ref = randomlist[0]
for i in randomlist:
if (1 - (i / ref)) * 100 > Degradation:
ref = i
continue
My code isn't considering that.
Could you please provide any help ? Would be thankful for that.
EDIT :
CodePudding user response:
If I understood right what you did is reducing by 5% of the current value.
What you should do is reducing by a constant value or a percentage of the initial value. So it would be -0.05 at each loop.
randomlist = [1, 0.98, 0.95, 0.93, 0.9, 0.87, 0.85, 0.82, 0.8, 0.78, 0.75, 0.72, 0.7]
Degradation = 10
five_percent_Degradation = Degradation * 0.05
ref = randomlist[0]
for i in randomlist:
if (1 - (i / ref)) * 100 > Degradation:
ref = i
Degradation -= five_percent_Degradation
print(Degradation)
CodePudding user response:
I managed to find the solution :
randomlist = [1, 0.98, 0.95, 0.93, 0.9, 0.87, 0.85, 0.82, 0.8, 0.78, 0.75, 0.72, 0.7]
Degradation = 10
ref = randomlist[0]
for i in randomlist:
if round((ref - i) * 100) >= Degradation:
ref = i
continue
Thank you for your time.