Da ich das noch für diverse Statistiken brauche habe ich mir mal das Zusammengebastelt.
Hab nebenbei auch das erste mal mit GDI+ gearbeitet
Funktioniert nur zur berechnung einer Regressionsgeraden! Für die anderen braucht man das Gauß-Verfahren mit Matritzen... leider hab ich noch keine ahnung wie ich sowas per script lösen lasse -.-
Bin mir ziemlich sicher das es sich noch optimieren lässt aber fürs erste genügt es mir
Der Code:
Spoiler anzeigen
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt("MustDeclareVars", 1)
Dim $input[6][2], $formel, $hgui, $gui, $graphic, $pos0, $pos1, $faktor, $width, $height, $padding_bottom
;Einstellungen GDI+
$faktor = 10
$width = 300
$height = 300
$padding_bottom = 10
;Werte für die Regression [][0] = x-wert, [][1] = f(x)-wert
$input[0][0] = 20
$input[0][1] = 0
$input[1][0] = 16
$input[1][1] = 3
$input[2][0] = 15
$input[2][1] = 7
$input[3][0] = 16
$input[3][1] = 4
$input[4][0] = 13
$input[4][1] = 6
$input[5][0] = 10
$input[5][1] = 10
$formel = getlreg($input)
MsgBox(0, "Formel:", "f(x) = "&$formel[0]&"x + ("& $formel[1] &") ")
$gui = GUICreate("Einfache Lineare Regression", $width, $height)
$hgui = WinGetHandle($gui)
GUISetState()
_GDIPlus_Startup ()
$graphic = _GDIPlus_GraphicsCreateFromHWND($hgui)
For $i = 0 To UBound($input)-1
_GDIPlus_GraphicsFillRect($graphic, $input[$i][0]*$faktor, $height-$padding_bottom-$input[$i][1]*$faktor, 5, 5)
Next
$pos0 = 0*$formel[0] + $formel[1]
$pos1 = $width*$formel[0] + $formel[1]
_GDIPlus_GraphicsDrawLine($graphic, 0*$faktor, $height-$padding_bottom-$pos0*$faktor, $width*$faktor, $height-$padding_bottom-$pos1*$faktor)
_GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func getlreg(ByRef $array)
Local $average, $new[2], $out[2]
If Not IsArray($array) Then
SetError(1)
Return 0
EndIf
$average = getav($array)
For $i = 0 To UBound($array)-1
$new[0] += ($array[$i][0] - $average[0]) * ($array[$i][1] - $average[1])
$new[1] += ($array[$i][0] - $average[0]) ^ 2
Next
$out[0] = $new[0] / $new[1]
$out[1] = $average[0] - ($new[0] / $new[1]) * $average[1]
Return $out
EndFunc
Func getsum(ByRef $array)
Local $out[2]
If Not IsArray($array) Then
SetError(1)
Return 0
EndIf
For $i = 0 To UBound($array)-1
$out[0] += $array[$i][0]
$out[1] += $array[$i][1]
Next
Return $out
EndFunc
Func getav(ByRef $array)
Local $sums, $out[2]
$sums = getsum($array)
$out[0] = $sums[0] / UBound($array)
$out[1] = $sums[1] / UBound($array)
Return $out
EndFunc