Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > Аналог функций ДИСПР?


Автор: WaReZMEN 26.5.2008, 08:55
Есть в Excel ДИСПР никто не знает как ее сделать вдельфи?

Автор: Frees 26.5.2008, 09:48
а что за функция а то у меня эксель английскй

Автор: Alexeis 26.5.2008, 12:15
  Конкретно ДИСПР не знаю, но вот фрагмент интерфейса модуля Math, возможно что-то из этого подойдет, я с английскими названиями стат. функцие не очень smile.


Код

{-----------------------------------------------------------------------
Statistical functions.

Common commercial spreadsheet macro names for these statistical and
financial functions are given in the comments preceding each function.
-----------------------------------------------------------------------}

{ Mean:  Arithmetic average of values.  (AVG):  SUM / N }
function Mean(const Data: array of Double): Extended;

{ Sum: Sum of values.  (SUM) }
function Sum(const Data: array of Double): Extended register;
function SumInt(const Data: array of Integer): Integer register;
function SumOfSquares(const Data: array of Double): Extended;
procedure SumsAndSquares(const Data: array of Double;
  var Sum, SumOfSquares: Extended) register;

{ MinValue: Returns the smallest signed value in the data array (MIN) }
function MinValue(const Data: array of Double): Double;
function MinIntValue(const Data: array of Integer): Integer;

function Min(const A, B: Integer): Integer; overload; inline;
function Min(const A, B: Int64): Int64; overload; inline;
function Min(const A, B: Single): Single; overload; inline;
function Min(const A, B: Double): Double; overload; inline;
function Min(const A, B: Extended): Extended; overload; inline;

{ MaxValue: Returns the largest signed value in the data array (MAX) }
function MaxValue(const Data: array of Double): Double;
function MaxIntValue(const Data: array of Integer): Integer;

function Max(const A, B: Integer): Integer; overload; inline;
function Max(const A, B: Int64): Int64; overload; inline;
function Max(const A, B: Single): Single; overload; inline;
function Max(const A, B: Double): Double; overload; inline;
function Max(const A, B: Extended): Extended; overload; inline;

{ Standard Deviation (STD): Sqrt(Variance). aka Sample Standard Deviation }
function StdDev(const Data: array of Double): Extended;

{ MeanAndStdDev calculates Mean and StdDev in one call. }
procedure MeanAndStdDev(const Data: array of Double; var Mean, StdDev: Extended);

{ Population Standard Deviation (STDP): Sqrt(PopnVariance).
  Used in some business and financial calculations. }
function PopnStdDev(const Data: array of Double): Extended;

{ Variance (VARS): TotalVariance / (N-1). aka Sample Variance }
function Variance(const Data: array of Double): Extended;

{ Population Variance (VAR or VARP): TotalVariance/ N }
function PopnVariance(const Data: array of Double): Extended;

{ Total Variance: SUM(i=1,N)[(X(i) - Mean)**2] }
function TotalVariance(const Data: array of Double): Extended;

{ Norm:  The Euclidean L2-norm.  Sqrt(SumOfSquares) }
function Norm(const Data: array of Double): Extended;

{ MomentSkewKurtosis: Calculates the core factors of statistical analysis:
  the first four moments plus the coefficients of skewness and kurtosis.
  M1 is the Mean.  M2 is the Variance.
  Skew reflects symmetry of distribution: M3 / (M2**(3/2))
  Kurtosis reflects flatness of distribution: M4 / Sqr(M2) }
procedure MomentSkewKurtosis(const Data: array of Double;
  var M1, M2, M3, M4, Skew, Kurtosis: Extended);

{ RandG produces random numbers with Gaussian distribution about the mean.
  Useful for simulating data with sampling errors. }
function RandG(Mean, StdDev: Extended): Extended;


Автор: Rrader 26.5.2008, 12:27
Код

Function Dispersion(Data: Array Of Real): Real;
Var
  I, J: Integer;
  Expectation: Real;
  SExp: Real;
Begin
  Result := 0;
  Expectation := 0;
  SExp := 0;
  J := High(Data);
  For I := 0 To J Do
  Begin
    Expectation := Expectation + Data[I];
    SExp := SExp + Sqr(Data[I]);
  End;
  Inc(J);
  Expectation := Expectation / J;
  SExp := SExp / J;
  Result := SExp - Sqr(Expectation);
End;

Procedure TForm1.Button1Click(Sender: TObject);
Begin
  ShowMessage(FloatToStr(Dispersion([10, 11])));
  ShowMessage(FloatToStr(Dispersion([10, 11, 40, 50, 60])));
End;

Автор: ama_kid 26.5.2008, 12:37
Цитата(WaReZMEN @  26.5.2008,  08:55 Найти цитируемый пост)
Есть в Excel ДИСПР никто не знает как ее сделать вдельфи? 
Цитата
Уравнение для ДИСПР имеет следующий вид: 
ДИСПР(число1;число2; ...) = SUM(i=1,N)[(X(i) - Mean)**2]/n
Если я правильно понял - то для получения аналога надо функцию
Код
{ Total Variance: SUM(i=1,N)[(X(i) - Mean)**2] }
function TotalVariance(const Data: array of Double): Extended;
разделить на количество элементов в генеральной совокупности n.

Автор: WaReZMEN 27.5.2008, 00:17
Всем спасибо!!!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)