Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quadratic Factorization

Started by ironbox Nov 4, 2004 at 2:20 PM 7 replies 1.1k views
Original Post
ironbox
ironbox
Im trying to make a program that takes inputs for a,b,c (ax^2+bx+c) and turns it into ex. (x-2)(x-5). i need to know some algorithm, but i dont. does someone know one.
jperalta
jperalta
You could try the quadratic formula. x = (-b (+/-) sqrt(b^2 - 4ac))/2a. If 4ac > b^2 then you have imaginary roots, if 4ac = b^2 you have a repeated real root and if 4ac < b^2 you have two unique real roots.
joanusdmentia
joanusdmentia
Sounds suspiciously like homework.....

Anyway, here's a hint. Rearrange both equations (ie. ax2+bx+c=0 and (x+m)(x+n)=0) until they are of similar form. With this you will be able to create 2 equations that equate some combination of m and n with some combination of a,b and c. Solve these equations simultaneously and you'll have your answer.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
Dmytry
Dmytry
Well, it's probably homework.
Anyway.
[google] clickster with title of this thread entered into search field.(hint: 3rd result)
Also, you'd better find roots using general formula and plug 'em as m and n
joanusdmentia
joanusdmentia
Quote:
Original post by Anonymous Poster
Quote:
Original post by joanusdmentia
Anyway, here's a hint. Rearrange both equations (ie. ax2+bx+c=0 and (x+m)(x+n)=0) until they are of similar form. With this you will be able to create 2 equations that equate some combination of m and n with some combination of a,b and c. Solve these equations simultaneously and you'll have your answer.

Could you, please, show how you plan to solve it like that?
If x^2 + px + q = (x-m)(x-n)
you get:
m + n = -p
mn = q
But solving this system is equivalent to solving a quadratic equation, so this does not help the original problem (i.e. it's the same). That is if I haven't missed something.

Yes, it is still solving a quadratic. The important difference is that you're no longer solving the quadratic for x, but for n and m.

Here's another way to do the same thing. For (x+m)(x+n)=0 to be true then one of (x+m) or (x+n) must also equal 0 (or both if m=n). This happens when m=-x and n=-x respectively (remember that x has 2 different roots, even if they are equal). Now all you have to do is solve for x.....
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
LilBudyWizer
LilBudyWizer
I think it depends upon what you are doing. The original question was about factorization of a polynomial. mn=q isn't real helpful when m and n can by any real number. The set of all such pairs is infinite. When the set of all such pairs is finite it is a differant story. An example is when m and n are limited to integers. There are only two such pairs then, i.e. (x,y) and (-x,-y). Further x and y have to be factors of q. It may seem contrived to limit it to integers, but you have no such reservation about limiting it to reals.
Keys to success: Ability, ambition and opportunity.
Fruny
Fruny
Homework.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.