Fits simple exponential equation to data.
The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation:
Example 1
In the following example we generate some data. Then we fit simple exponential function to this data and retreive it's regression coefficients. Uses MathExpr, MtxVecTee, Series, RegModels;
procedure Example(Series1, Series2: TLineSeries);
var Y,YHat,B,X: Vector;
begin
X.Size(100);
Y.Size(X);
X.Ramp(-5,0.05); // X = (-5, -4.95, ...-0.05)
Y.RandGauss(3.5,0.12); // populate sample data
ExpFit(B,X,Y); // calculate coefficients
ExpEval(B.Values,X,YHat); // evaluate y by using calculated coefficients
DrawValues(X,Y,Series1); // draw original data
DrawValues(X,YHat,Series2); // draw fitted data
end;
#include "MtxVecCpp.h"
#include "Math387.hpp"
#include "RegModels.hpp"
#include "MtxVecTee.hpp"
void __fastcall Example(TLineSeries* Series1, TLineSeries* Series2);
{
Vector X,Y;
Vector B, YHat;
X->Size(100,false);
Y->Size(X);
X->Ramp(-5.0, 0.05); // x= -5, -4.95, ...-0.05
Y->RandGauss(3.5, 0.12); // sample data
ExpFit(B,X,Y,NULL); // calculate coefficients
// evaluate y by using calculated coefficients
ExpEval(B->Values,X, YHat);
DrawValues(X,Y,Series1,false); // draw original data
DrawValues(X,YHat,Series2,false); // draw fitted data
}
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
private void Example(Steema.TeeChart.Styles.Line line1,
Steema.TeeChart.Styles.Line line2)
{
Vector X = new Vector(100);
Vector Y = new Vector(100);
Vector B = new Vector(0);
Vector YHat = new Vector(0);
X.Ramp(-5.0, 0.05); // x= -5.0, -4.95, ... -0.05
Y.RandGauss(3.5, 0.12); // sample data
// calculate coefficients
RegModels.ExpFit(B,X,Y,null);
// evaluate y by using calculated coefficients
RegModels.ExpEval(B.Values,X, YHat);
MtxVecTee.DrawValues(X,Y,line1,false);
MtxVecTee.DrawValues(X,YHat,line2,false);
}
}