In the following example we generate some data. Then we fit power function to this data and retreive it's regression coefficients.
Uses MtxExpr, MtxVecTee, Series, RegModels; procedure Example(Series1: 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 FracFit(B,X,Y,2,4); // calculate coefficients, no constant term // evaluate y by using calculated coefficients FracEval(B.Values,X,YHat,2); DrawValues(X,Y,Series1); // draw original data DrawValues(X,YHat,Series2); // draw fitted data end;
#include "MtxExpr.hpp" #include "Math387.hpp" #include "RegModels.hpp" #include "MtxVecTee.hpp" void __fastcall Example(TLineSeries* Series1, TLineSeries* Series2); { sVector X,Y; sVector 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 FracFit(B,X,Y,2,4); // calculate coefficients // evaluate y by using calculated coefficients FracEval(B,X, YHat,2,false); DrawValues(X,Y,Series1,false); // draw original data DrawValues(X,YHat,Series2,false); // draw fitted data }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
|