Sign in to follow this  
Followers 0
Ultima2

Script acting weird

2 posts in this topic

#1 ·  Posted (edited)

Im trying to write a script for solving quadratic equation using Laguerre's method.

#include <GUIConstants.au3>
#include <Math.au3>

$hMainGUI = GUICreate("Laguerre's Method",800,500)

GUISetBkColor(999999)
GUISetFont(9)

$tab2 = GUICtrlCreateTabItem("2nd Degree")
$exitbutton = GUICtrlCreateButton("Exit", 530, 400, 50, 50)
$A2value = GUICtrlCreateInput("",110,158,30,22)
$B2value = GUICtrlCreateInput("", 182, 158, 30, 22)
$C2value = GUICtrlCreateInput("", 252, 158, 30, 22)
$ok2button = GUICtrlCreateButton("ok", 240, 300, 25, 25)
$seed = GUICtrlCreateInput("", 310, 230, 40, 22)
GUICtrlCreateLabel("Enter seed", 305, 206)
GUICtrlCreateLabel("X^2",140, 168)
GUICtrlCreateLabel("+",166, 162)
GUICtrlCreateLabel("X", 212, 168)
GUICtrlCreateLabel("+", 232, 162)
GUICtrlCreateLabel("Put in the form of ax^2 +bx +c", 107, 130)

Guisetstate()
Do
    $msg = GUIgetmsg()
    Select
        Case $msg = $ok2button
            Call("math")
        Case $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton
            Exit
    EndSelect
Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton
Func math()
    $avalue = GuictrlRead($A2value)
    $bvalue = GUICtrlRead($B2value)
    $cvalue = GUIctrlread($C2value)
    $x = GUICtrlRead($seed)
    $i=1
    While $i< 7
    $G = (2*($avalue)*($x) + $bvalue)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)
    $H = ($G)^2 - (2*($avalue) + 1)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)
    $z = Sqrt((2-1)*(2*($H) - ($G)^2))
    $a = (2/(($G)+$z))
    $x = $x - $a
    $i = $i + 1
    WEnd
    MsgBox(0, "the root is?", $x)
EndFunc

The quadratic equation that im using to test this is 3x^2 -10x + 4, which has 2 real roots. The problem Im getting is that some integers that I enter as a seed do not produce any result... For example when I put in 3 or 4 as a seed value, it returns the root for me accurate up to the 10e-11 place. But when I enter 1 or 2 as a seed value, it returns me -1.#IND? A seed of 0 also return me a root, so why doesn't 1 or 2? Is there something wrong in my script that is causing the value 1 or 2 to return -1.#IND?

I googled it, could this be caused because the data im using is in float format or something?

Edited by Ultima2

Share this post


Link to post
Share on other sites



Im trying to write a script for solving quadratic equation using Laguerre's method.

CODE
#include <GUIConstants.au3>

#include <Math.au3>

$hMainGUI = GUICreate("Laguerre's Method",800,500)

GUISetBkColor(999999)

GUISetFont(9)

$tab2 = GUICtrlCreateTabItem("2nd Degree")

$exitbutton = GUICtrlCreateButton("Exit", 530, 400, 50, 50)

$A2value = GUICtrlCreateInput("",110,158,30,22)

$B2value = GUICtrlCreateInput("", 182, 158, 30, 22)

$C2value = GUICtrlCreateInput("", 252, 158, 30, 22)

$ok2button = GUICtrlCreateButton("ok", 240, 300, 25, 25)

$seed = GUICtrlCreateInput("", 310, 230, 40, 22)

GUICtrlCreateLabel("Enter seed", 305, 206)

GUICtrlCreateLabel("X^2",140, 168)

GUICtrlCreateLabel("+",166, 162)

GUICtrlCreateLabel("X", 212, 168)

GUICtrlCreateLabel("+", 232, 162)

GUICtrlCreateLabel("Put in the form of ax^2 +bx +c", 107, 130)

Guisetstate()

Do

$msg = GUIgetmsg()

Select

Case $msg = $ok2button

Call("math")

Case $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton

Exit

EndSelect

Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton

Func math()

$avalue = GuictrlRead($A2value)

$bvalue = GUICtrlRead($B2value)

$cvalue = GUIctrlread($C2value)

$x = GUICtrlRead($seed)

$i=1

While $i< 7

$G = (2*($avalue)*($x) + $bvalue)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)

$H = ($G)^2 - (2*($avalue) + 1)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)

$z = Sqrt((2-1)*(2*($H) - ($G)^2))

$a = (2/(($G)+$z))

$x = $x - $a

$i = $i + 1

WEnd

MsgBox(0, "the root is?", $x)

EndFunc

The quadratic equation that im using to test this is 3x^2 -10x + 4, which has 2 real roots. The problem Im getting is that some integers that I enter as a seed do not produce any result... For example when I put in 3 or 4 as a seed value, it returns the root for me accurate up to the 10e-11 place. But when I enter 1 or 2 as a seed value, it returns me -1.#IND? A seed of 0 also return me a root, so why doesn't 1 or 2? Is there something wrong in my script that is causing the value 1 or 2 to return -1.#IND?

I googled it, could this be caused because the data im using is in float format or something?

Using a seed of 2, the problem happens before it gets -1.#IND, when $i = 6, $G = -1.#INF (infinity), that results in unexpected divide by zero operations that in turn give you -1.#IND. Run it this way to see where the failure happens:
Func math()
     $avalue = GuictrlRead($A2value)
     $bvalue = GUICtrlRead($B2value)
     $cvalue = GUIctrlread($C2value)
     $x = GUICtrlRead($seed)
     $i=1
     While $i< 7
        $G = (2*($avalue)*($x) + $bvalue)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)
        ConsoleWrite("$i = " & $i & "  $G = " & $G & @LF)
        $H = ($G)^2 - (2*($avalue) + 1)/(($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)
        ConsoleWrite("$i = " & $i & "  $H = " & $H & @LF)
        $z = Sqrt((2-1)*(2*($H) - ($G)^2))
        ConsoleWrite("$i = " & $i & "  $z = " & $z & @LF)
        $a = (2/(($G)+$z))
        ConsoleWrite("$i = " & $i & "  $a = " & $a & @LF)
        $x = $x - $a
        $i = $i + 1
    WEnd
    MsgBox(0, "the root is?", $x)
EndFunc

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0