Factorising quadratic trinomials where the coefficient of X^2 is not 1

Started by
15 comments, last by Zahlman 18 years, 8 months ago
I don't think it's a requirement. If you don't like that, you'll hate the result of x2+2x+3.

Also, note the square root. Since there's two results for it, there's actually two possible answers. For your example -2x2-13x-15, the two possible answers are (-2*x-10)*(x+1.5) and (-2*x-3)*(x+5). If you don't like one answer, feel free to try the other.

[Edited by - smart_idiot on July 24, 2005 3:32:54 AM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Advertisement
How would i code it to produce both answers?

(Note - VB doesn't have complex numbers!)

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Just calculate it twice, using the positive and negative roots, i.e., change e=b/a/2+sqrt(b*b-(4*a*c))/a/2 to e=b/a/2-sqrt(b*b-(4*a*c))/a/2 for the second time.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Ok, good.

I've got it working now.

But a small problem.
for "-2X^2 + 13X + 25"

The answer it spits back is (-2X + 16.1046863561493)(X + 1.55234317807464)

Which isn't very right.

It does produce the right answer "(-2X - 3)(X + 5)" to your equasion "-2x^2 - 13x - 15" tho.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Maxima gives me this:

(%i1) expand((-2*X+16.1046863561493)*(X+1.55234317807464));                     2(%o1)           - 2 X  + 13.00000000000002 X + 25.0000000000001


Looks like -2X^2 + 13X + 25 to me.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Hmmm.

Ow well, good. (just wish it had infintie precision tho).

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
You could tell it to output square root values symbolically rather than actually evaluating them... you might want to make a class like so:

// very not tested!class squareRootFraction {  // represents sqrt(num/denom).  int num, denom;  void reduce() {    int div = gcd(num, denom); // todo: implement    num /= div; denom /= div;  }  public:  squareRootFraction(int num, int denom = 1) : num(num), denom(denom) {    reduce();  }  squareRootFraction& operator /= (int x) {    denom *= x*x; reduce(); return *this;  }  squareRootFraction& operator *= (int x) {    num *= x*x; reduce(); return *this;  }  friend ostream& operator<<(ostream& os, const squareRootFraction& me) {    os << "sqrt(" << me.num << "/" me.denom << ")";    return os;  }}

This topic is closed to new replies.

Advertisement