You are here: Symbol Reference > Statistics Namespace > Functions > Statistics.Covariance Function
Stats Master VCL
ContentsIndex
Example

Calculate the covariance matrix from two vectors representing two variables.

var Data1, Data2: Vector;
  CovMtx : Matrix;
begin
  Data1.SetIt(false,[1.2,3]);
  Data2.SetIt(false,[5,5.5]);
  Covariance(Data1,Data2,CovMtx,False);
    // cov = [1.62, 0.45,
    //        0.45, 0.125]
end;
#include "MtxExpr.hpp"
#include "Statistics.hpp"
void __fastcall Example()
{
    sVector data1,data2;
    sMatrix cov;
    data1.SetIt(false,OPENARRAY(double,(1.2,3)));
    data2.SetIt(false,OPENARRAY(double,(5,5.5)));
    Covariance(data1,data2,cov,false);
    // cov = [1.62, 0.45,
    //        0.45, 0.125]
}
Copyright (c) 1999-2025 by Dew Research. All rights reserved.