Sign in to follow this  
Followers 0
WolfWorld

A simple Eq. calculator

2 posts in this topic

#1 ·  Posted (edited)

Its abit messy

just put an eq. down like 2+5*7+x=90

only with a val. of x

it still got some bug in it like the eq. above it should be 53 but it show 53.0000000000005 but it still work

$input = InputBox('Eq', 'f')

$s = StringSplit($input, '=')
If $s[0] <> 2 Then Exit
$x = 1
$j = .1
$l = 0
$ml = -1
$swz = 0
While 1
    If $ml = 1 Then $x -= $j
    If $ml = 0 Then $x += $j
    If $swz = 0 Then
        If $l = $x Then $j = StringTrimRight($j, 1) & '01'
    EndIf
    $side1 = Execute(StringReplace($s[1], 'x', '(' & $x & ')'))
    $side2 = Execute(StringReplace($s[2], 'x', '(' & $x & ')'))
    If $side1 > $side2 Then $ml = 1
    If $side1 < $side2 Then $ml = 0
    If $side1 = $side2 Or StringLen($j) > 10 Then
        MsgBox(0, '', 'Found a solution ' & $x)
        Exit
    EndIf
    ConsoleWrite($side1 & ' : ' & $side2 & ' : ' & $x & @CRLF)
    If $swz = 0 Then
        $swz = 1
        $l = $x
    Else
        $swz = 0
    EndIf
WEnd
Edited by athiwatc

Share this post


Link to post
Share on other sites



if you want to solve equations numerally, why dont you use newton iteration or the fixed point iteration?

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