Mat Posted December 3, 2009 Posted December 3, 2009 (edited) Quite simple, but very useful for homeworks! Currently allows you to select either Completing the square or the formula, factorising is a too hard...It returns complete working, so your teacher will never know.Download it hereMat Edited December 3, 2009 by Mat AutoIt Project Listing
jennico Posted December 3, 2009 Posted December 3, 2009 very nice, thx. i wish my son would script something like this instead of WoW.... this reminds me of a long time planned project of mine: a universal calculator with math plugins by anyone who wants to contribute.... some time maybe. keep on ! j. Reveal hidden contents 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
d0n Posted December 4, 2009 Posted December 4, 2009 very cool, wish i had this when i was in High school
Mat Posted December 4, 2009 Author Posted December 4, 2009 Thanks guys I have had a more in depth look at how to factorise on a computer... and have now given up completely. Maybe if one of the maths genius' out there want to have a look? Mat AutoIt Project Listing
BrettF Posted December 4, 2009 Posted December 4, 2009 Search for Project Euler on here. Many problems there involved factorization... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Mat Posted December 4, 2009 Author Posted December 4, 2009 On 12/4/2009 at 8:48 AM, 'BrettF said: Search for Project Euler on here. Many problems there involved factorization... ?? I'll have a look but I mean factorizing like: x^2 + x - 20 = 0 (x + 5)(x - 4) = 0 therefore x1 = -5 x2 = 4 I don't think i saw that on project euler (at least the ones we did in autoit) you should also remember I own that project page on google Mat AutoIt Project Listing
Achilles Posted December 4, 2009 Posted December 4, 2009 Just mathly speaking.. If both your x's are integers, than you could just say you factored it. E.g. x^2 + 7x + 12 works out by the formula to be x=3 and x=4. Therefore: (x-3)(x-4) is your factored equation. That's a kind of ghetto way of doing it.. but it works. I haven't thought of the negatives of using this... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Mat Posted December 4, 2009 Author Posted December 4, 2009 On 12/4/2009 at 9:01 AM, 'Achilles said: Just mathly speaking.. If both your x's are integers, than you could just say you factored it.E.g. x^2 + 7x + 12 works out by the formula to be x=3 and x=4. Therefore: (x-3)(x-4) is your factored equation. That's a kind of ghetto way of doing it.. but it works. I haven't thought of the negatives of using this...Thats really clever. As in... Very very very clever. Defeats the point ever so slightly but very clever.Thanks a lot achilles i'll put that in the next version with a big shiny badge for you Mat AutoIt Project Listing
czardas Posted December 4, 2009 Posted December 4, 2009 (edited) Nice program Mat. I'm guessing that to factorize (when the first term is X^2) you could try finding all the factors for C and seeing if they add up to B. If A <> 1 OR A <> -1 Then ...I'm not sure. Edited December 4, 2009 by czardas operator64 ArrayWorkshop
Mat Posted December 4, 2009 Author Posted December 4, 2009 Thanks again for more info... I am going to use achilles method, as it is by far the easiest. Though I may look at doing it properly for a bit of fun later on. Mat AutoIt Project Listing
Achilles Posted December 4, 2009 Posted December 4, 2009 On 12/4/2009 at 11:11 AM, 'Mat said: Thats really clever. As in... Very very very clever. Defeats the point ever so slightly but very clever.Thanks a lot achilles i'll put that in the next version with a big shiny badge for you Matlol, thanks... I'm glad all my high school and college education has paid off somewhere. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Mat Posted December 4, 2009 Author Posted December 4, 2009 (edited) Only problem is when A is not 1. Thats the only reason I haven't released it yet. 10x^2 + 13x - 30 (2x + 5)(5x - 6) This can't be factorised by my program as it does not return integer results (1.2 and -2.5 I think...) Mat Edit: More replies than downloads. Doesn't say much for the program Edited December 4, 2009 by Mat AutoIt Project Listing
czardas Posted December 4, 2009 Posted December 4, 2009 (edited) On 12/4/2009 at 6:23 PM, 'Mat said: Only problem is when A is not 1. Thats the only reason I haven't released it yet. 10x^2 + 13x - 30 (2x + 5)(5x - 6) This can't be factorised by my program as it does not return integer results (1.2 and -2.5 I think...) Mat Edit: More replies than downloads. Doesn't say much for the program Ok this adds a new element, but the problem can be broken down. You need to test all factors of A against all factors of C while trying to derive B Call the factors of A... a1 and a2 And the factors of C... c1 and c2 Now test all factors of A against all factors of C until you find a match for the following equation: a1*c2 + a2*c1 = B And the resulting factorization will be: (a1x + c1)(a2x + c2) Edited December 4, 2009 by czardas operator64 ArrayWorkshop
Mat Posted December 4, 2009 Author Posted December 4, 2009 Yep... Now put it into practice... Its harder than you make it sound. Thanks a lot though, its helping me to understand how it works as well as getting this program written. Mat AutoIt Project Listing
Achilles Posted December 5, 2009 Posted December 5, 2009 On 12/4/2009 at 6:23 PM, 'Mat said: Only problem is when A is not 1. Thats the only reason I haven't released it yet.10x^2 + 13x - 30 (2x + 5)(5x - 6)This can't be factorised by my program as it does not return integer results (1.2 and -2.5 I think...)MatEdit: More replies than downloads. Doesn't say much for the program I knew there was something too simple about my solution... Maybe check rational numbers to see if they are something simple (e.g. .2 or .5 or .3333333333333..) and if they are just add the necessary coefficients) I don't know, that's still doing stuff the ghetto way. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
jeanbern Posted December 5, 2009 Posted December 5, 2009 here's a neat trick called rational root test if you have a_n*x^n + a_n-1 * x^n-1 + ... + a_1*x + a_0 (in this case just ax^2 + bx + c) then the only possible rational roots are +-p/q where p and q are integers dividing a_0 and a_n respectively not super useful but nice to know and can be adapted for finding rational solutions to this now for your problem at hand suppose you know ax^2 + bx + c factors as (dx+e)(fx+g) then working backwards you can do the following: ax^2 + bx + c = ax^2 + (ef)x + (dg)x + c = fx(dx+e) + g(dx+e) = (dx+e)(fx+g) which is how a student might be expected to show work without using the quadratic formula all that's left for you is to be able to take a fraction and express it as it's numerator and denominator
Malkey Posted December 5, 2009 Posted December 5, 2009 MatYou inspired me to try this.A Mini Quadratic Solver based on the formula, $x = InputBox("Values of X", 'Example entry "1x^2 + 0x - 9"', "1x^2 + 0x - 9", "", 50, 50, 150, 100) $ans = Execute(StringRegExpReplace($x, "(.*?)(x\^2)(.*?)(x)(.*)", "((-(${3})+(((${3})*(${3}))-(4*${1}*(${5})))^0.5)/(2*${1}))")) $ans1 = Execute(StringRegExpReplace($x, "(.*?)(x\^2)(.*?)(x)(.*)", "((-(${3})-(((${3})*(${3}))-(4*${1}*(${5})))^0.5)/(2*${1}))")) MsgBox(0, "Results", 'For "' & $x & ' = 0"' & @CRLF & @CRLF & "x = " & $ans & @CRLF & " or " & @CRLF & "x = " & $ans1)
czardas Posted December 5, 2009 Posted December 5, 2009 (edited) On 12/4/2009 at 7:58 PM, 'Mat said: Yep... Now put it into practice... Its harder than you make it sound.Thanks a lot though, its helping me to understand how it works as well as getting this program written.MatOk, here's an attempt (written in AutoIt Version: 3.2.6.0) I guess there's no difference in this particular script.expandcollapse popup#include <Array.au3> Dim $arrayA[1], $arrayC[1], $A = 10, $B = 13, $C = -30 ;Values from the example above $P = $A ; Patch added to negate final expression (not ideal) If $A < 0 Then ; Force a positive coefficient for x^2 $A = -$A $B = -$B $C = -$C EndIf For $i = 1 To Int($A^.5) Step 1 ;List divisors for $A If Mod($A, $i) = 0 Then _ArrayAdd($arrayA,$i&","&$A/$i) EndIf Next $numC = $C If $C < 0 Then ; Might as well use positive integers to determine the divisors $numC = -$C EndIf For $i = 1 To Int($numC^.5) Step 1 ;List divisors for $numC If Mod($numC, $i) = 0 Then _ArrayAdd($arrayC,$i&","&$numC/$i) EndIf Next $factorization = "Could not factorize the expression!" For $i = 1 To UBound($arrayA) -1 Step 1 ; Test each pair of divisors from $arrayA $divsA = StringSplit($arrayA[$i], ",") For $j = 1 To UBound($arrayC) -1 Step 1 ; Tested against each pair of divisors from $arrayC $divsC = StringSplit($arrayC[$j], ",") If $C > 0 Then ; divsC have the same sign If $divsA[1]*$divsC[2] + $divsA[2]*$divsC[1] = $B Then $factorization = "("&$divsA[1]&"x + "&$divsC[1]&")("&$divsA[2]&"x + "&$divsC[2]&")" ;(x + n)(x + n) ElseIf $divsA[1]*$divsC[2] + $divsA[2]*$divsC[1] = -$B Then $factorization = "("&$divsA[1]&"x - "&$divsC[1]&")("&$divsA[2]&"x - "&$divsC[2]&")" ;(x - n)(x - n) EndIf ElseIf $C < 0 Then ; divsC have opposite signs If $divsA[1]*$divsC[2] - $divsA[2]*$divsC[1] = $B Then $factorization = "("&$divsA[1]&"x - "&$divsC[1]&")("&$divsA[2]&"x + "&$divsC[2]&")" ;(x - n)(x + n) ElseIf $divsA[2]*$divsC[1] - $divsA[1]*$divsC[2] = $B Then $factorization = "("&$divsA[1]&"x + "&$divsC[1]&")("&$divsA[2]&"x - "&$divsC[2]&")" ;(x + n)(x - n) EndIf EndIf Next Next If $P < 0 Then ; Patch added to negate final expression (not ideal) $factorization = "-"&$factorization EndIf MsgBox(0, "Factorization", $factorization)I'm sure the script can probably be simplified or improved in other ways. It also needs testing for different values of $A, $B and $C. Perhaps I made a mistake. This script does not cater for coefficient values of zero. Those variations should be treated as special cases.Edit1: I forgot to escape the loop when a solution is found. Return values of '1x' can be substituted for plain 'x', but I'm too tired to alter it right now.Edit2: After looking at this again, I notice that I also forgot to negate the final expression when $A starts out with a negative value. This is required because I forced $A to have a positive value. Perhaps this is the wrong approach. I have added a temporary patch for the time being (4 lines). This is not a solution! I will have to rewrite the code (as it's now become far too messy) and include factorization for when coefficients of A, B or C are equal to zero. Edited December 5, 2009 by czardas operator64 ArrayWorkshop
Mat Posted December 5, 2009 Author Posted December 5, 2009 Surely if you are multiplying by -1 thoughout then it does not matter. 2x^2 + 4x - 5 = 0 is the same as -2x^2 - 4x + 5 = 0 Reveal hidden contents 2x^2 + 4x - 5 = -2x^2 - 4x + 5 2x^2 + 4x = -2x^2 - 4x + 10 x^2 + 2x = -(x^2) - 2x + 5 2x^2 + 4x - 5 = 0(and I ever doubted it... ) So I'm not sure what your referring to there. I had written a nice long reply to everyone else, but it got eaten by the big forum monster, and I seriously can't be asked to write it all out again. basically, Well done everyone . New version is due to be released in 10 secs and counting. Thanks a lot to the work of czardas, the final code for factorizing is based very much on what he's done above, with me polishing it off ever so slightly. Mat AutoIt Project Listing
czardas Posted December 5, 2009 Posted December 5, 2009 (edited) On 12/5/2009 at 7:10 PM, 'Mat said: Surely if you are multiplying by -1 thoughout then it does not matter.MatHmm yes! Well I think that's only true providing that the expression equals zero; which is true in this case, so just forget the 4 lines that I added, which are not a good solution anyway. However, you might want to consider scenarios where the user wishes to factorize without knowing the value of the expression. Perhaps that's something for a future release. Still, I'm glad that the above code was helpful to you. Edited December 5, 2009 by czardas operator64 ArrayWorkshop
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