Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Algorithmen (https://www.delphipraxis.net/28-library-algorithmen/)
-   -   Delphi Linear Curve Fitting (https://www.delphipraxis.net/96481-linear-curve-fitting.html)

mschnell 25. Jul 2007 08:17


Linear Curve Fitting
 
Liste der Anhänge anzeigen (Anzahl: 1)
Im Rahmen eines Praktikums haben wir eine Unit mit Funktionen für lineare Kurven-Intepolation und Ausgleichsrechnung erstellt.

Kurve-Fitting ist "Ausgleichsrechnung". d.h. die (mehreren) konstanten Parameter einer Funktion y=f(x) (= f(x, ai) mit i=0..N-1)) werden so bestimmt, dass die Kurve y=f(x) "möglichst nah" an vorgegebenen Punkten (xj/yj, j := 0...M-1 vorbeigeht. Hierbei heiß "möglichst nah vorbei" dass die Summe der Quadrate der Differenzen (yj-f(xj) (für j := 0...M-1 ) minimiert wird.

Das lässt sich für lineare Konstanten ("Koeffizienten") der Funktion auf ein lineares Gleichungssystem zurückführen und deterministisch lösen ("lineare Ausgleichsrechnung" Beispiel: Polynom-Approximation). Das macht diese Unit.

Für nichtlinear verwendete Parameter ("nicht lineare Ausgleichsrechnung" Beispiel: Exponential-Approxmation) wird ein rekursives Verfahren benötigt. (Haben wir schon programmiert, lade ich hoch, wenn diese Unit soweit klar ist).

Ausgleichsrechnung / Kurven-Approximation braucht man immer, wenn man eine Menge von Werte-Paaren durch eine Funktion, von der man die Struktur, nicht aber das genaue Aussehen kennt, repräsentieren will um weitere Werte (Extrapolation oder Interpolation) zu bestimmen. Die Güte (Sigma) der Approximation gibt einen Hinweis darauf, wie richtig das Modell ist und/oder wie fehlerbehaftet die Messwerte sind.


Es wird die unit "Matrix" verwendet, die sich ebenfalls in der "Algorithmen"-Kategorie der Library befindet.

-Michael

Delphi-Quellcode:
unit LinApprox;

// Copyright: Julian und Michael Schnell, Krefeld, Germany, [email]mschnell@bschnell.de[/email]


interface
  uses Matrix;

type
  TFuncI = function(x: extended; i: Integer): extended;

function LinInterpolation(V: TMatrix; FuncI: TFuncI): TVector;
// interpolates the points given in V by a linear combination of functions
//
//     N-1
// y = Sum (a[i] * Funci(x, i)
//    i = 0
//
// V:     matrix containing N points (Xi/Yi)
// Funci: Functions fi to be fitted
//
// Result: vector containing the linear factors a[i]

function LinApproximation(V: TMatrix; N: Integer; FuncI: TFuncI): TVector; overload;
function LinApproximation(V: TMatrix; N: Integer; FuncI: TFuncI;
         out Sigma: Extended): TVector; overload;
// performs a linear approximation of the points given in V by a linear combination of functions
//
//     N-1
// y = Sum (a[i] * Funci(x, i)
//    i = 0
//
// using least square analysis
//
// V:    matrix containing M points (Xi/Yi)
// N:    Count of functions to be used
// Funci: Functions fi to be fitted
// Sigma: (optional) Standard deviation of the Model
//        (requesting Sigma adds a considerable calculation)
//
// Result: vector containing the linear factors a[i]
//
// if N=M the result is the same as with LinInterpolation and Sigma is 0
[edit=Matze]Beschreibungstext aus einem anderen Beitrag ergänzt. MfG, Matze[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:20 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz