Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: Implementing a moving average Pin
Ralf Meier15-Feb-18 21:27
mveRalf Meier15-Feb-18 21:27 
There is also another way to build this Average without using an array - but the base-problem is the same : it is necessary to know what the code does and how it works.
Independant from this - here is another Code-Solution :
C#
int CountAct = 0;
double ValueLast = 0;

public double getAverage(double actValue, int Smoothing)
{
    if (Smoothing < 1)
        Smoothing = 1;
    CountAct = Math.Min(CountAct + 1, Smoothing);
    double myDivider = Math.Max((double)CountAct - 1, 0);
    double Result = (ValueLast * myDivider + actValue) / (myDivider + 1);
    ValueLast = Result;
    return Result;
}

Here you can build an average from as much values you like - you only have to tell the method the smoothing-value you like to have ...

modified 16-Feb-18 6:33am.

GeneralRe: Implementing a moving average Pin
auting8216-Feb-18 1:25
auting8216-Feb-18 1:25 
GeneralRe: Implementing a moving average Pin
Pete O'Hanlon16-Feb-18 7:53
mvePete O'Hanlon16-Feb-18 7:53 
GeneralRe: Implementing a moving average Pin
Ralf Meier16-Feb-18 9:49
mveRalf Meier16-Feb-18 9:49 
GeneralRe: Implementing a moving average Pin
auting8216-Feb-18 11:40
auting8216-Feb-18 11:40 
GeneralRe: Implementing a moving average Pin
Ralf Meier16-Feb-18 12:42
mveRalf Meier16-Feb-18 12:42 
GeneralRe: Implementing a moving average Pin
Ralf Meier17-Feb-18 0:14
mveRalf Meier17-Feb-18 0:14 
GeneralRe: Implementing a moving average Pin
auting8217-Feb-18 0:36
auting8217-Feb-18 0:36 
AnswerRe: Implementing a moving average Pin
Ralf Meier17-Feb-18 0:53
mveRalf Meier17-Feb-18 0:53 
GeneralRe: Implementing a moving average Pin
auting8217-Feb-18 1:13
auting8217-Feb-18 1:13 
GeneralRe: Implementing a moving average Pin
Ralf Meier17-Feb-18 3:30
mveRalf Meier17-Feb-18 3:30 
AnswerRe: Implementing a moving average Pin
Ralf Meier17-Feb-18 3:50
mveRalf Meier17-Feb-18 3:50 
GeneralRe: Implementing a moving average Pin
auting8217-Feb-18 7:40
auting8217-Feb-18 7:40 
GeneralRe: Implementing a moving average Pin
Ralf Meier17-Feb-18 10:11
mveRalf Meier17-Feb-18 10:11 
GeneralRe: Implementing a moving average Pin
auting8218-Feb-18 8:40
auting8218-Feb-18 8:40 
GeneralRe: Implementing a moving average Pin
Ralf Meier18-Feb-18 9:32
mveRalf Meier18-Feb-18 9:32 
GeneralRe: Implementing a moving average Pin
auting8227-Feb-18 21:33
auting8227-Feb-18 21:33 
AnswerRe: Implementing a moving average Pin
Gerry Schmitz15-Feb-18 8:16
mveGerry Schmitz15-Feb-18 8:16 
Question.NET - choose correct service for conversion Pin
Bulgarin14-Feb-18 4:54
Bulgarin14-Feb-18 4:54 
AnswerRe: .NET - choose correct service for conversion Pin
Gerry Schmitz14-Feb-18 6:40
mveGerry Schmitz14-Feb-18 6:40 
Questioncreating trial version and expiry date issue Pin
Mou_kol14-Feb-18 0:30
Mou_kol14-Feb-18 0:30 
AnswerRe: creating trial version and expiry date issue Pin
Pete O'Hanlon14-Feb-18 0:38
mvePete O'Hanlon14-Feb-18 0:38 
GeneralRe: creating trial version and expiry date issue Pin
Mou_kol15-Feb-18 21:16
Mou_kol15-Feb-18 21:16 
AnswerRe: creating trial version and expiry date issue Pin
Eddy Vluggen14-Feb-18 3:22
professionalEddy Vluggen14-Feb-18 3:22 
AnswerRe: creating trial version and expiry date issue Pin
OriginalGriff14-Feb-18 4:30
mveOriginalGriff14-Feb-18 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.