Quadratic Factoring

This is a discussion on Quadratic Factoring within the C++ Programming forums, part of the General Programming Boards category; This is actually for my TI-83+ calculator, but the problem can go to most any language. First, assuming the general ...

  1. #1
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640

    Quadratic Factoring

    This is actually for my TI-83+ calculator, but the problem can go to most any language. First, assuming the general equation:
    Ax^2+Bx+C=0

    and given A, B, and C it is possible to solve for X using the quadratic equations:

    (-B + sqrt(b^2-4AC))/(2A)
    and
    (-B - sqrt(b^2-4AC))/(2A)

    to find two answers. However some times there is only one answer and sometimes imaginary numbers. (This isn't my problem however). What I need to accomplish is factoring the equation down not using the quadratic equation. For instance:

    X^2 - 4X + 4 = 0

    down to:

    (X - 2) (X - 2)
    which is also
    (X - 2)^2

    This method is sometimes called FOIL, how can you accomplish this through programming? Please help.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #2
    Unregistered
    Guest
    (X + A)*(X + B) == X^2 + 2(A + B) + A * B

    You need to write a program to solve for A and B.

    I assume you want A and B to be whole numbers, so start by factoring the constant and using those values as hints for A and B.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I already made one of those. If you want, I can probably email it to you or maybe even post it here.


    Edit: You will have to wait till I get back to school because I have it saved there.
    Last edited by golfinguy4; 04-15-2002 at 05:04 PM.

  4. #4
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Ok, but what can I do to get A and B? I'm confused.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Could you post it? I forgot to mention that I'm not looking for specific code, but I could probably learn alot from your code.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    To start, make sure that the discriminant is a rational number. Then, use for loops to go through the possible values.

  7. #7
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    How do you calculate possible values?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  8. #8
    Unregistered
    Guest
    Factor the constant if you are assuming that everything is a whole number.

  9. #9
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Huh? I don't understand what you're talking about, Unregistered. Is there some algorithim that solves for multiples of a number?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  10. #10
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Originally posted by Unregistered
    (X + A)*(X + B) == X^2 + 2(A + B) + A * B

    You need to write a program to solve for A and B.

    I assume you want A and B to be whole numbers, so start by factoring the constant and using those values as hints for A and B.
    Shouldn't that be:
    X^2+2X(A+B) + A*B?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  11. #11
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    wait, is this what happens? Is this true?

    (X+ (-b+sqrt(b2-4ac))/(2a)) * (X+ (-b-sqrt(b2-4ac))/(2a)) = X2 + 2X(A+B) + A*B
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  12. #12
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Ax2 + Bx + C = 0
    so, two multiples of C must add up to B, (this is for simple purposes, assuming for now that A==1)

    ok, here's some pseudo code I came up with:

    if B>0 {
    for (int j=1;j<=B;j++){
    if j * (B-j) == C {
    //found a working factor?
    }
    }
    }


    is this ok? this is the simplist I've come up with yet, but would it work assuminb B is positive?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quadratic formula in c
    By cakestler in forum C Programming
    Replies: 2
    Last Post: 02-08-2009, 09:41 PM
  2. quadratic probing (collision resolution) problem
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2006, 12:30 PM
  3. Quadratic Function
    By abs.emailverify in forum C Programming
    Replies: 5
    Last Post: 11-14-2006, 02:07 PM
  4. gluSphere and quadratic objects
    By phil_drew in forum Game Programming
    Replies: 2
    Last Post: 11-11-2003, 02:17 AM
  5. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21