Hey =D
Ich habe vor einer Weile ein Skript zum Intervallhalbierungsverfahren geschrieben und habe mir gedacht, dass ich es hier reinstelle!
Villeicht kann jemand damit etwas anfangen =D
Skript:
Spoiler anzeigen
#Region ### Include ================================================
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#EndRegion ### Include ================================================
#Region ### Opt ================================================
Opt('TrayAutoPause', 0)
Opt('GUICloseOnESC', 0)
#EndRegion ### Opt ================================================
#Region ### Global & Dim ================================================
Global $fx1, $fx2, $fm
Dim $x1n[1], $x2n[1], $m[1]
#EndRegion ### Global & Dim ================================================
#Region ### GUI-Main ================================================
$gui = GUICreate("Intervallhalbierungsverfahren", 333, 147, 192, 124)
$inp_funk = GUICtrlCreateInput("f(x)=0,5-0,5*x-x^3", 136, 8, 129, 21)
$label1 = GUICtrlCreateLabel("Funktion des Graphen:", 8, 8, 130, 19)
GUICtrlSetFont(-1, 9, 800, 0, "Arial")
$label2 = GUICtrlCreateLabel("Für:", 8, 40, 25, 19)
GUICtrlSetFont(-1, 9, 800, 0, "Arial")
$inp_x1 = GUICtrlCreateInput("-0,5", 32, 40, 25, 21, $ES_AUTOHSCROLL)
$Label3 = GUICtrlCreateLabel("<x<", 64, 40, 25, 19)
GUICtrlSetFont(-1, 9, 800, 0, "Arial")
$inp_x2 = GUICtrlCreateInput("1,0", 96, 40, 25, 21, $ES_AUTOHSCROLL)
$button = GUICtrlCreateButton("Berechnen", 8, 88, 75, 25, $WS_GROUP)
$Label4 = GUICtrlCreateLabel("Anzahl der Iterationen:", 8, 64, 131, 19)
GUICtrlSetFont(-1, 9, 800, 0, "Arial")
$inp_zahl = GUICtrlCreateInput("10", 144, 64, 25, 21, BitOR($ES_AUTOHSCROLL, $ES_NUMBER))
$Label5 = GUICtrlCreateLabel("x0=", 8, 120, 25, 19)
GUICtrlSetFont(-1, 9, 800, 0, "Arial")
$inp_out = GUICtrlCreateInput("", 40, 120, 130, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
$button_child = GUICtrlCreateButton("Interations Prozess", 232, 120, 97, 25, $WS_GROUP)
GUISetState(@SW_SHOW, $gui)
#EndRegion ### GUI-Main ================================================
#Region ### GUI-Child ================================================
$gui_child = GUICreate("Iterations Prozess", 331, 331, 544, 126, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$hListView = _GUICtrlListView_Create($gui_child, "", 0, 0, 330, 330)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_InsertColumn($hListView, 0, "Schritt", 50)
_GUICtrlListView_InsertColumn($hListView, 1, "Mittelpunkt (x0)", 200)
GUISetState(@SW_HIDE, $gui_child)
#EndRegion ### GUI-Child ================================================
MsgBox(48, "Achtung!", 'Bitte bei der Funktion des Graphen ein "*" einsetzen!' & @CRLF & 'Also statt "3x" - "3*x" einsetzen!' & @CRLF & @CRLF & 'Und Hochzahlen mit "^" schreiben! Also z.b.: x^2')
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg[1]
[/autoit] [autoit][/autoit] [autoit]Case $gui
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
Case $button_child
_ShowChild()
Case $button
_ArrayEmpty($x1n)
_ArrayEmpty($x2n)
_ArrayEmpty($m)
$iter = GUICtrlRead($inp_zahl)
Dim $x1n[$iter]
Dim $x2n[$iter]
Dim $m[$iter]
$funk = GUICtrlRead($inp_funk)
$split_funk = StringSplit($funk, "=")
If $split_funk[0] > 2 Then
MsgBox(48, "Achtung!", 'Bitte nur eine Funktion mit einem "=" eingeben!')
Else
GUICtrlSetData($inp_out, _Iteration($split_funk[2], GUICtrlRead($inp_x1), GUICtrlRead($inp_x2), $iter))
EndIf
EndSwitch
Case $gui_child
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
_HideChild()
EndSwitch
EndSwitch
WEnd
Func _ExeF($funkt, $wert)
$aus = Execute(StringRegExpReplace(StringReplace(StringReplace($funkt, "x", "(" & $wert & ")"), ",", "."), "[^0123456789*/+-/^()]", ""))
Return $aus
EndFunc ;==>_ExeF
Func _Iteration($funkf, $x1f, $x2f, $anz)
If _ExeF($funkf, $x1f) > 0 Then
$fx1 = True
Else
$fx1 = False
EndIf
If _ExeF($funkf, $x2f) > 0 Then
$fx2 = True
Else
$fx2 = False
EndIf
If $fx1 = $fx2 Then
MsgBox(48, "Achtung!", 'Im Bereich ' & $x1f & ' < x < ' & $x2f & ' wurde keine Nullstelle gefunden!')
Else
$m[0] = Execute(StringRegExpReplace(("(" & StringReplace((("(" & $x1f & ")" & "+" & "(" & $x2f & ")")), ",", ".") & ")" & "/2"), "[^0123456789*/+-/^()]", ""))
If _ExeF($funkf, $m[0]) > 0 Then
$fm = True
Else
$fm = False
EndIf
If $fm = $fx1 Then
$x1n[0] = $m[0]
$x2n[0] = $x2f
ElseIf $fm = $fx2 Then
$x1n[0] = $x1f
$x2n[0] = $m[0]
EndIf
If $anz = 1 Then
Return $m[0]
Else
For $a = 1 To ($anz - 1)
If _ExeF($funkf, $x1n[$a-1]) > 0 Then
$fx1 = True
Else
$fx1 = False
EndIf
If _ExeF($funkf, $x2n[$a-1]) > 0 Then
$fx2 = True
Else
$fx2 = False
EndIf
$m[$a] = Execute(StringRegExpReplace(("(" & StringReplace((("(" & $x1n[$a-1] & ")" & "+" & "(" & $x2n[$a-1] & ")")), ",", ".") & ")" & "/2"), "[^0123456789*/+-/^()]", ""))
If _ExeF($funkf, $m[$a]) > 0 Then
$fm = True
Else
$fm = False
EndIf
If $fm = $fx1 Then
$x1n[$a] = $m[$a]
$x2n[$a] = $x2n[$a-1]
ElseIf $fm = $fx2 Then
$x1n[$a] = $x1n[$a-1]
$x2n[$a] = $m[$a]
EndIf
Next
Return $m[$a-1]
EndIf
EndIf
EndFunc ;==>_Iteration
Func _ShowChild()
_GUICtrlListView_DeleteAllItems($hListView)
For $i = 0 to UBound($m)-1
_GUICtrlListView_AddItem($hListView, $i+1)
_GUICtrlListView_AddSubItem($hListView, $i, $m[$i], 1)
Next
GUISetState(@SW_SHOW, $gui_child)
EndFunc
Func _HideChild()
GUISetState(@SW_HIDE, $gui_child)
EndFunc
Func _ArrayEmpty(ByRef $array)
; Prog@ndy
If Not isArray($array) Then Return SetError(1,0,0)
Switch UBound($array,0)
Case 1
Dim $array[UBound($array,1)]
Case 2
Dim $array[UBound($array,1)][UBound($array,2)]
Case 3
Dim $array[UBound($array,1)][UBound($array,2)][UBound($array,3)]
Case Else
Return SetError(2,0,0)
EndSwitch
Return 1
EndFunc
MfG Tobi