DexterMorgan Posted March 15, 2008 Share Posted March 15, 2008 Oh my God i can't belive i didnt notice this topic before! It is really cool. I will definiatly use all this stuff to cheat in math. HAHa Lol. I was wondering if AutoIt can solve multistep equations Like 3x-23+25=4x-45+54x And it would solve for the Variable It would be really cool if it works Thank you code Link to comment Share on other sites More sharing options...
martin Posted March 15, 2008 Share Posted March 15, 2008 If $a = 0 then in the quadratic formula:-b +- sqrt( (b^2) - (4*a*c)) 2aThen when you divide by 2a, are you not dividing by zero? thus undefined?No, that is just blindly applying a formula when the formula doesn't apply. If a = 0 then you have0*x^2 + b*x +c = 0therefore b*x + c = 0so, if b is not zero then x = -c/bwhich is what my modified version of your function returns.You can argue that if a is zero then you haven't got a quadratic, which is true, it's just that if a is zero then anyone could work the answer out and to have a clever function say it hadn't got a clue what to do is a shame. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
crashdemons Posted March 20, 2008 Share Posted March 20, 2008 (edited) oh lol, I made mine in PHP when I was struggling to figure out some values - I seriously have never seen anybody else mention it, was starting to wonder if anybody else knew about it. Edit: I was trying to quote a reply to my post but the quote got garbled with data - eh. Edited March 20, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
monoceres Posted March 20, 2008 Share Posted March 20, 2008 Do you know what would be really great? I mathematical expression parser, like this: _ParseExpression("58*Sin(90)")Have been trying to make one myself several times but it just is to complex for me Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Malkey Posted March 20, 2008 Share Posted March 20, 2008 Do you know what would be really great? I mathematical expression parser, like this: _ParseExpression("58*Sin(90)")Have been trying to make one myself several times but it just is to complex for me You could look at some previous posts :-http://www.autoitscript.com/forum/index.ph...st&p=374121and http://www.autoitscript.com/forum/index.ph...st&p=474934 Link to comment Share on other sites More sharing options...
Toady Posted March 20, 2008 Share Posted March 20, 2008 Do you know what would be really great? I mathematical expression parser, like this: _ParseExpression("58*Sin(90)")Have been trying to make one myself several times but it just is to complex for me Execute() in help file. www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
crashdemons Posted March 21, 2008 Share Posted March 21, 2008 (edited) Probably the same thing as the quadratic functions listed but I made it looking at the equation a slightly different way. If it looks the same or doesnt work any faster, that's okay - I just wanted to try to make one. For Factoring or solving Trinomials where ax^2 + bx +c =q and a,b and c are defined EDIT: Fixed operations when ($a=0 and $b=0) and when ($a=0 and $b=0 and $c!=$q) expandcollapse popupFunc _ComSqr($a=0,$b=0,$c=0,$q=0,$solve_for='x') ;$solve_for ;x = solve for x ;0 = solve for 0 (aka factor) ; ^^^NOTICE: this MIGHT NOT produce integers ;ans = returns whether you have 0,1 or 2 answers, etc. ; No Solution Returns '' ; Infinite returns 'inf' Local $qq='',$result='',$sol1='',$sol2='', $ans=0,$z=0, $xinf=false If $a=0 Then ;bx+c=q or c=q $q-=$c If $b=0 Then $xinf=true ; 0x+c=0 X is infinite but you can still solve for 0 (0=0) If $q<>0 Then return ''; if c=q then q-c=0 Else If $b<>0 Then $q/=$b EndIf Else ;ax^2+bx+c=q $q-=$c $q/=$a $b/=$a $z=$b/2 $q+=$z^2 $c=$z If $q<0 then return $result $q=Sqrt($q) $qq=(-1*$q)-$c $q-=$c EndIf Switch $solve_for Case 'ans' If $xinf Then Return 'inf' If StringLen($q )>0 Then $ans+=1 If StringLen($qq)>0 Then $ans+=1 $result=$ans Case 'x' If $xinf Then Return 'inf' $result=$q&','&$qq If $q=$qq Then $result=$q If $q=='' Or $qq=='' Then $result=$q&$qq Case '0' If $xinf Then Return $q ; q, which is 0 :D $sol1='(x+'&(-1*$q)&')' $sol2='(x+'&(-1*$qq)&')' If $q=='' Then $sol1='' If $qq=='' Then $sol2='' $result=$sol1&$sol2 If $sol1==$sol2 and StringLen($result)>0 Then $result=$sol1&'^2' $result=StringReplace(StringReplace(StringReplace($result,'+-','-'),'(x+0)','(x)'),'(x-0)','(x)') EndSwitch Return $result EndFunc Edited March 21, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted May 1, 2008 Share Posted May 1, 2008 Need some operations ABOVE exponentiation (really big / really small numbers?)I wrote the following based upon the Wikipedia article on Iterated Powers of Tetration_MultExp(2, 4) should solve for: (see image)and_IterExp(2, 2, 3) should solve for: (see image)Func _MultExp($a, $n) ;Multilevel exponentiation ;- Example: _MultExp(2, 4)==(2^(2^(2^(2)))) If $n<0 Then $a=1/$a $n*=-1 EndIf $b=1 Select Case $n=1 $b=$a Case $n>1 $b=$a $exp=1 For $i=1 To $n $b=$a^$exp $exp=$b Next EndSelect Return $b EndFunc Func _IterExp($a, $b, $n) ;Iterated Exponentiation ;- Examples: _IterExp(1, 2, 3)==((((1)^2)^2)^2)==1^(2^3) ; _IterExp(2, 2, 3)==((((2)^2)^2)^2)==2^(2^3) Return $a^($b^($n)) EndFunc My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
james3mg Posted May 1, 2008 Share Posted May 1, 2008 Script Function: Tests if a number is even or odd. Returns 1 - If the number is even. Returns 2 - If the number is odd. #ce ---------------------------------------------------------------------------- Func _IsEven($eVal) Local $a = $eVal / 2 Select Case Round($a, 0) = $a Return 1 Case Round($a, 0) <> $a Return 0 EndSelect EndFuncIt looks to me like it returns 0 if it's odd, and 1 if it's even, not 1 and 2 for even and odd... and it would be simpler to use: Func _IsEven($eVal) Return Not BitAND($eVal,1) EndFunc this returns false (0) if it's odd, and true (1) if it's even, just like yours appears to Also, this will work with decimal numbers; if I'm not mistaken, 5280.3 is considered even (though not whole), but your function would return that it's odd. "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
crashdemons Posted November 2, 2008 Share Posted November 2, 2008 (edited) Anyone post something like this yet?ConsoleWrite( 'Pi = ' & SumPi( 0, 9 ) & @LF ); only 14 decimal places anyway... Func SumPi( $iMin, $iMax) Local $Sum = 0 For $k = $iMin To $iMax $Sum += 1/16^$k * ( 4/(8*$k+1) - 2/(8*$k+4) - 1/(8*$k+5) - 1/(8*$k+6) ) Next Return $Sum EndFuncFrom:EDIT: it is also said you can use part of it to extract binary/hexadecimal digits from Pi (not decimal,) but I can't figure it out. Edited November 2, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
clarinetmeister Posted November 21, 2008 Share Posted November 21, 2008 Dunno if this will help any of you, but here's a formula that solves a quadratic given the values for a, b, c, and the array in which to put the two solutions. Always returns 1, but changes values in input array into the solution values. It also works for quadratics with imaginary roots! (form a + bi) CODEFunc QuadraticFormula($a, $b, $c, ByRef $Array) If $b ^ 2 - 4 * $a * $c < 0 Then ; Negative discriminant $disc = -1 * ($b ^ 2 - 4 * $a * $c) $imaginary_part = $disc / (2 * $a) $imaginary_coefficient = $imaginary_part & "i" $real_coefficient = (-1 * $ / (2 * $a) $ans_1 = $real_coefficient & " + " & $imaginary_coefficient $ans_2 = $real_coefficient & " - " & $imaginary_coefficient Else $disc = $b ^ 2 - 4 * $a * $c ; Positive discriminant $ans_1 = (-1 * $b + Sqrt($disc)) / (2 * $a) $ans_2 = (-1 * $b - Sqrt($disc)) / (2 * $a) EndIf If $ans_1 = $ans_2 Then $stat = 1 ; number of distinct solutions Else $stat = 2 ; number of distinct solutions EndIf $Array[0] = $stat $Array[1] = $ans_1 $Array[2] = $ans_2 Return (1) EndFunc ;==>QuadraticFormula Link to comment Share on other sites More sharing options...
Malkey Posted November 21, 2008 Share Posted November 21, 2008 Dunno if this will help any of you, but here's a formula that solves a quadratic given the values for a, b, c, and the array in which to put the two solutions. Always returns 1, but changes values in input array into the solution values. It also works for quadratics with imaginary roots! (form a + bi) This is pretty good, clarinetmeister. It does return a complex number solution when called for. Here is a working example with your QuadraticFormula() function to save people time checking it out. expandcollapse popup#include <array.au3> Local $Array[3] ; for results ;quadratic equation 2x^2 + 3x + 7 = 0 QuadraticFormula(2, 3, 7, $Array) _ArrayDisplay($Array, "2x^2 + 3x + 7 = 0") ; Display results Local $Array[3] ; for results ;quadratic equation x^2 - 8x + 16 = 0 QuadraticFormula(1, -8, 16, $Array) _ArrayDisplay($Array, "x^2 - 8x + 16 = 0") ; Display results Func QuadraticFormula($a, $b, $c, ByRef $Array) Local $stat If $b ^ 2 - 4 * $a * $c < 0 Then ; Negative discriminant $disc = -1 * ($b ^ 2 - 4 * $a * $c) $imaginary_part = $disc / (2 * $a) $imaginary_coefficient = $imaginary_part & "i" $real_coefficient = (-1 * $b) / (2 * $a) $ans_1 = $real_coefficient & " + " & $imaginary_coefficient $ans_2 = $real_coefficient & " - " & $imaginary_coefficient Else $disc = $b ^ 2 - 4 * $a * $c ; Positive discriminant $ans_1 = (-1 * $b + Sqrt($disc)) / (2 * $a) $ans_2 = (-1 * $b - Sqrt($disc)) / (2 * $a) EndIf If $ans_1 = $ans_2 Then $stat = 1 ; number of distinct solutions Else $stat = 2 ; number of distinct solutions EndIf $Array[0] = $stat $Array[1] = $ans_1 $Array[2] = $ans_2 Return (1) EndFunc ;==>QuadraticFormula Link to comment Share on other sites More sharing options...
jennico Posted December 30, 2008 Share Posted December 30, 2008 (edited) _LCM (lowest common multiple)_HCF (highest common factor)_IsPrimewell, as for that and lots of other math functions please try my _Primes.au3 UDF.i made them with highest precision and best optimization.cheers j.as for LCM and HCF, there is an ancient algorithm called Euclidean Algorithm (though probably invented before Euclid). its efficiency is unbeatable. Edited December 30, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now