Hatte vor einiger Zeit mal den Gauß-Algorithmus nachprogrammiert und vllt kanns ja jmd brauchen:
VB.NET-Quellcode
- Public Structure QuadratFunction
- Public Sub New(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal y As Double)
- Me.x = a
- Me.y = b
- Me.z = c
- Me.f = y
- End Sub
- Public x As Double
- Public y As Double
- Public z As Double
- Public f As Double
- End Structure
- Public Class Gauß
- Public Shared Function Berechne(ByVal x As QuadratFunction, ByVal x2 As QuadratFunction, ByVal x3 As QuadratFunction) As QuadratFunction
- Dim coEffMatrix As Double()() = {New Double() {x.x, x.y, x.z, x.f},
- New Double() {x2.x, x2.y, x2.z, x2.f},
- New Double() {x3.x, x3.y, x3.z, x3.f}}
- Dim quotient As Double = coEffMatrix(0)(0)
- Dim potentax As Double = coEffMatrix(0)(0) / quotient
- Dim potentbx As Double = coEffMatrix(0)(1) / quotient
- Dim potentc As Double = coEffMatrix(0)(2) / quotient
- Dim potenty As Double = coEffMatrix(0)(3) / quotient
- Dim multiplicate As Double = -(coEffMatrix(1)(0) / potentax)
- Dim potentaxerg As Double = potentax * multiplicate
- Dim potentbxerg As Double = potentbx * multiplicate
- Dim potentcerg As Double = potentc * multiplicate
- Dim potentyerg As Double = potenty * multiplicate
- Dim multiplicate2 As Double = -(coEffMatrix(2)(0) / potentax)
- Dim potentaxerg2 As Double = potentax * multiplicate2
- Dim potentbxerg2 As Double = potentbx * multiplicate2
- Dim potentcerg2 As Double = potentc * multiplicate2
- Dim potentyerg2 As Double = potenty * multiplicate2
- Dim newMatrix As Double()() = {New Double() {potentax, potentbx, potentc, potenty},
- New Double() {potentaxerg + coEffMatrix(1)(0), potentbxerg + coEffMatrix(1)(1), potentcerg + coEffMatrix(1)(2), potentyerg + coEffMatrix(1)(3)},
- New Double() {potentaxerg2 + coEffMatrix(2)(0), potentbxerg2 + coEffMatrix(2)(1), potentcerg2 + coEffMatrix(2)(2), potentyerg2 + coEffMatrix(2)(3)}}
- Dim newMultiplication As Double = newMatrix(1)(1)
- Dim newPotentbx As Double = newMatrix(1)(1) / newMultiplication
- Dim newPotentc As Double = newMatrix(1)(2) / newMultiplication
- Dim newPotenty As Double = newMatrix(1)(3) / newMultiplication
- Dim expo As Double = -(newMatrix(0)(1) / newPotentbx)
- Dim newExpobx As Double = newMatrix(0)(1) + (newPotentbx * expo)
- Dim newExpoc As Double = newMatrix(0)(2) + (newPotentc * expo)
- Dim newExpoy As Double = newMatrix(0)(3) + (newPotenty * expo)
- Dim expo3 As Double = -(newMatrix(2)(1) / newPotentbx)
- Dim newExpobx3 As Double = newMatrix(2)(1) + (newPotentbx * expo3)
- Dim newExpoc3 As Double = newMatrix(2)(2) + (newPotentc * expo3)
- Dim newExpoy3 As Double = newMatrix(2)(3) + (newPotenty * expo3)
- Dim endMatrix As Double()() = {New Double() {newMatrix(0)(0), newExpobx, newExpoc, newExpoy},
- New Double() {newMatrix(1)(0), newPotentbx, newPotentc, newPotenty},
- New Double() {newMatrix(2)(0), newExpobx3, newExpoc3, newExpoy3}}
- Dim func As Double = endMatrix(2)(2) / endMatrix(2)(2)
- Dim CErgebniss As Double = endMatrix(2)(3) / endMatrix(2)(2)
- Dim poterstzeile As Double = -endMatrix(0)(2)
- Dim axErgebniss As Double = CErgebniss * poterstzeile + endMatrix(0)(3)
- Dim bxErgebniss As Double = -endMatrix(1)(2) * CErgebniss + endMatrix(1)(3)
- Return New QuadratFunction(axErgebniss, bxErgebniss, CErgebniss, 0)
- End Function