Monday, November 28, 2005

Factoring Program

I've written a program that can help a lot with factoring trinomials. I wrote it in C++ first, but then I ported it to TIBasic for graphing calculators. The windows exe version of this program can be found here, the C++ source is here, and the TI verson is here. Of course, that file is only useful if you have a link cable to connect your computer to your calculator. If you don't, talk to me during the day and I'll give you the program. Both the computer and the calculator version pause after their finished. To continue, hit enter. The calculator version also pauses after the screen is filled up so that you'll have time to check the displayed factors. Anyway, it's pretty simple. There are basically eight different types of quadratic trinomial patterns. There's 1++ (ex. x^2+6x+5), 1+-, 1-+, and 1--. Then there's a++ (ex. 5x^2+10x+5), a+-, a-+, and a-- (where a!=1). I'm going to explain how to use my program for each type of pattern. For 1++, 1--, and 1+- patterns, type the value of c (ax^2+bx+c=y) when the program says "c=?" or "number: ". Then match b with the number in the parentheses. The two numbers on either side of the colon are your factors. For example, let's assume you have x^2+20x+36. You would enter 36 for c. The computer (or calculator) would then print:
1:36(37)
2:18(20)
3:12(15)
4:9(13)
6:6(12)
9:4(13)
12:3(15)
18:2(20)
36:1(37)
You would see that the second factor - 2:18(20) - matches b. So your answer is (x+2)(x+18). 1-+ patterns are a tad more complex. For 1-+ patterns, enter c as usual. However, take the opposites of both of your factors and the number in the parentheses. For an example, let's use x^2-13x+36. The calculator gives you the same as above. However, knowing what you know, you invert each of the numbers:
-1:-36(-37)
-2:-18(-20)
-3:-12(-15)
-4:-9(-13)
-6:-6(-12)
-9:-4(-13)
-12:-3(-15)
-18:-2(-20)
-36:-1(-37)
Thus, you'll see that the factors are (x-4)(x-9) because -13=b. Now you're wondering why I even bothered to make this program. After all, 1** patterns are really easy to do in your head. The usefulness of this comes when you're doing a** patterns. For a** patterns, enter c*a for "c=?" or "number: ". Then take the factors and divide the divisible factor by a. More often than not, that will get you the correct answer. However, it is also possible that you'll need to divide both sides by factors of a. For example, 2x^2-11x+15. Enter the number 30 and take the opposites (because the is a -+ pattern) and you'll get:
-1:-30(-31)
-2:-15(-17)
-3:-10(-13)
-5:-6(-11)
-6:-5(-11)
-10:-3(-13)
-15:-2(-17)
-30:-1(-31)
As you can see, the fourth factor is the correct answer, since -11=b. Since you know that -5 is not divisible by 2, you can tell that your factors will be (2x-5)(x-6). Not too complex once you get used to it. Wow, that explanation sucked. If anyone would care to rewrite it in a comment, please go ahead.

14 Comments:

At Mon Nov 28, 06:24:00 PM , Blogger Asif said...

Just thought I'd mention this: to factor over rationals, all you really have to do is use the just use the rational zeros theorem. If ax^2+bx+c, than the POSSIBLE rational zeros are (factors of a)/(factors of c). If none of those turn out to be solutions, you can't factor over rationals.

 
At Mon Nov 28, 07:31:00 PM , Blogger Eric said...

So how would I use that to factor a trinomial into binomials?

 
At Mon Nov 28, 07:38:00 PM , Blogger Asif said...

I don't know... divide a out of the equation first. Then find all the possible rational zeros. Then test each one into the original equation. If it works, negate it and put x in front of it and parentheses around it. It is not perfect because for all the factors x-c c might not be an integer, but you should be guaranteed to get something like:
a(x-c1)(x-c2) where a is a and c1 and c2 are rational roots. If the trinomial doesn't have rational roots, you're out of luck, but that stands for the existing program too. If I have time I might try and write a Java command prompt factor thing too, but I would really love to get something that uses synthetic division to factor stuff like cubics and up.

 
At Mon Nov 28, 09:58:00 PM , Blogger Calvin August said...

This comment has been removed by a blog administrator.

 
At Mon Nov 28, 10:00:00 PM , Blogger Calvin August said...

all i can say is...


:0


Ps: eric if u need help with problems like 5+9=13, 3+4=7, I charge $10.00 an hour :)

 
At Mon Nov 28, 10:00:00 PM , Blogger Calvin August said...

""can you catch how dumb i am in my last post :0

 
At Tue Nov 29, 03:54:00 PM , Blogger Eric said...

Calvin, you may be stupid, but I'm not. Anyway, 3+4=7 is a statement, not a problem... And why the hell didn't anyone tell me that I could find the factors using the roots? Okay, Asif did, but I didn't have the slightest clue what he was saying.

 
At Tue Nov 29, 06:13:00 PM , Blogger Eric said...

Okay, now what I need to know is how to seperate the numerator and denomerator of a fraction out in a program. Better yet, how do I convert a decimal to a simplified fraction?

 
At Tue Nov 29, 06:16:00 PM , Blogger Eric said...

Asif, how do you use synthetic division to factor something? I understand how to check factors with it (read a website that was stupid but understandable), but how do you actually factor? What numbers would you set the division up with, I mean.

 
At Tue Nov 29, 06:42:00 PM , Blogger Asif said...

OK. So first you get the possible rational factors using the leading coefficient and the constant value (this works for any polynomial, not just trinomials.).

Then, you do synthetic division with each of the resulting fractions. But you don't actually do synthetic division, because all you really have to do is plug the number into the polynomial and see if you get 0. if you do, it is a root and a factor in the form (x-c) (c is the root) can be created. You have to make sure that you have the same number of rational zeros as the degree of the polynomial, because otherwise it doesn't factor completely over rationals (I'm assuming you don't want to try and get quadratic factors, and complex number factors and all that jazz because that would get really complex really fast).

So if you had: x^3 - 2x^2 - x + 2, you would get a list of all possible rational zeros: +/-1, +/-2. Then you check each in turn, and get solutions for +/-1 and 2. Then you just write that as: (x-1)(x+1)(x-2).

Also, I just remembered: somewhere in the program you would have to check for multiplicities (i.e. a factor that is sqaured or cubed or something).

 
At Tue Nov 29, 06:53:00 PM , Blogger Asif said...

Oh yeah, one final thought. In the source for your current factor program link in the blog, you factor by taking number 1 and dividing it by every number less than it until you go through all the numbers. I'm not going to pretend to understand any of the wacko factor algorithms they use to factor 200-digit numbers, but wouldn't it be simpler if you just used the square root of the number as a limit? You'd get every integer factor.

 
At Thu Dec 01, 07:21:00 PM , Blogger Eric said...

Yeah, it would. I never know how to do all of this, so I just hack up some crap to make it work. Wow, that was dumb. Okay, here's a slightly more complex example of what you said to make sure I grasp the method. 2x^4+x^3-19x^2-9x+9=0
Factors of leading term: 2,1
Factors of the constant term: 1,9,3
According to sparknotes, possible rational zeros are factors of the constant term over factors of the leading term. Thus, the possible zeros are (+/- for all of these): 1/2,1,9/2,9,3/2,3. Plugging these back in, you find that 1/2, 3, -1, and -3 are rational roots. So it factors to (x-.5)(x-3)(x+1)(x+3), right? So to make a program for that, all you have to do is find the factors of the leading and constant terms and then test them. Not that hard, is it?

 
At Thu Dec 01, 08:57:00 PM , Blogger Eric said...

I tried to write a program to do this in TIBasic, but it just didn't work. That and the fact that the TIBasic is really slow made me decide to write it in C++ first and then port it. Maybe by then I'll have figured out how to do this kind of stuff in assembly (much faster).

 
At Thu Dec 08, 06:41:00 PM , Blogger Motor.On said...

Okay Eric, do the last one. BDUH

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home