A simple Eq. calculator

Recommended Posts

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 on other sites

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