Quadratic Factoring Program

Name: Quadratic Factoring v1.1Author: Timothy FosterDownload: quadfact1.1.zipCompatibility: Parent page not setFile Size: 490 bytes |
This program will factor quadratic equations equal to 0, and it can factor quadratic expressions. The program identifies GCF and prime quadractic polynomials. |

Want to update this page?

Upload new filesto provide up-to-date versions of your program;or Edit the contentof this page to provide up-to-date information about your program.A moderator will only process these changes if you add the word

to theupdatelist of tags

## What the community thinks:

I created a quadratic factoring program. How does it fare? For some reason, it claims x

^{2}+2x+1 to be prime, but hopefully no one needs a program to factor that.Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

ReplyOptionsJust use the quadratic formula. Ax

^{2}+Bx+C factors as A(x-r_{1})(x-r_{2}), where r_{1}and r_{2}are the roots. To limit yourself to factoring over rational/integer polynomials, check if Ar_{1}and Ar_{2}are integers, and proceed accordingly.ReplyOptionsOf course… that way is definitely smaller. Why did I not think of that? Find the roots, and put it in the form, whereas mine processes the numbers which takes longer… what about unfactorable ones?

I also found the problem on the x

^{2}+2x+1.Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

ReplyOptionsi believe un-factorable ones would give a decimal value for sqrt(B²-4AC), or an imaginary value ;)

make sure you get into a+bi mode so the calculator will let you take the square root of a negative number.

ReplyOptionsWell, for imaginary numbers for sure, but decimal values do have roots.

(1)Maybe for irrational numbers, but those are hard to identify.

Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

ReplyOptionsmaybe use a decimal to fraction converter?

Thats all i could think of…

Unless you go back to the way you were doing it before, using factors and stuff, which seems more foolproof to me, but slower and larger.

'sigh' the age old battle between speed and reliability…

ReplyOptionsYou don't need a decimal to fraction converter unless the original equation also had decimals in it, which would defeat the entire point of factoring it.

First test if D=B²-4AC is nonnegative: if it's negative, then you know the polynomial is prime.

Then compute the roots r

_{1}and r_{2}. Test if Ar_{1}is an integer: if it has a fractional part, then you know the polynomial is prime. You don't need to test Ar_{2}if your coefficients are integers, since Ar_{1}+Ar_{2}=-B.Otherwise, the two factors are (Ax-Ar

_{1}) and (Ax-Ar_{2}). Factor the GCD from each of these terms. The integer factor in the factorization will be A divided by the product of the two GCDs — or at least, this has to be an integer if the coefficients A, B, and C were. Otherwise, you've just factored the polynomial over the rational numbers.No problems with reliability that I see.

ReplyOptionsoh…

i see…

ReplyOptions#here is the C answer

#include<stdio.h>

#include<math.h>

float a,b,c, roota, rootb,h,y,z,d,e,f,g,i,temp=1,lcm;

long int temp2, lcmtemp;

double lcd (double xx, double yy);

/* Declare values */

main()

{

/* (h)(dx+e)(fx+g) */

printf ("\nThis Program calculates the factors of quadratic equations");

printf ("\n(a) x*x + (b) x + (c)\n");

do

{

printf ("\nInput a=");

scanf("%f", &a);

printf ("\nInput b=");

scanf("%f", &b);

printf ("\nInput c=");

scanf("%f", &c);

if ((b*b-4*a*c)<0) printf ("\nnon solvable quadratic re-enter values\a\a\a");

}

while ((b*b-4*a*c)<0);

/* line 23 calcualtions of roots of quadratic equation*/

z=sqrt((b*b)-(4*a*c));

roota=((-b)-z)/(2*a);

rootb=((-b)+z)/(2*a);

printf ("\nroot1=%+f", roota);

printf ("\nroot2=%+f", rootb);

if (roota>0)

{

i=1;lcm=roota;}

else { i=-1;lcm=roota*(-1);};

/* Call function to calculate LCM for 1st root*/

y= lcd (1, lcm);

y=(long)(y*i+0.5*i);

y=y/1000000;

/* calculates d and e*/

/* (h)(dx+e)(fx+g) */

/*printf("\nLCD1=%f",y); */

e=(long)((((roota/y)+(0.5))*i*-1)*i);

d=(long)((1/y)+(0.5*i));

if (rootb>=0)

{

i=1;lcm=rootb;}

else { i=-1;lcm=rootb*(-1);};

/* Call function to calculate LCM for 2nd root*/

y= lcd (1,lcm);

y=(long)(y*i+0.5*i);

y=y/1000000;

/* calculates f and ge*/

/* (h)(dx+e)(fx+g) */

/*printf("\nLCD2=%f",y);*/

g=(long)((((rootb/y)+(0.5))*-1*i)*i);

f=(long)((1/y)+(0.5*i));

if (f<0) {f=f*-1;g=g*-1;};

if (d<0) {d=d*-1;e=e*-1;};

/* calculate h*/

h=(long)(a/(d*f));

/* (h)(dx+e)(fx+g) */

printf("\n(%f)(%fx+ %f) (%fx + %f)",h,d,e,f,g);

printf("\n\nCopyright Frank Hull");

return 0;

}

double lcd (double xx, double yy)

{

lcmtemp=(long) (yy*1000000+0.5);

temp2=(long) (xx*1000000+0.5);

while (lcmtemp!=temp2)

{

if (xx>yy)

{

z=xx-yy;

xx=z;

}

else

{

z=yy-xx;

yy=z;

}

lcmtemp=(long) (yy*1000000+0.5);

temp2=(long) (xx*1000000+0.5);

continue;

};

return (yy*1000000);

}

ReplyOptionsAnd who cares about a C version??

Sunrise 3 Progress: 30%

Size: around 20 KB, not including the save lists and in-game RAM.

ReplyOptionsThis is not your own work; you based the C version off of Timothy Foster's z80 TI-Basic version. You acquired the algorithm from T. Foster. So give him some credit, will you?

Sunrise 3 Progress: 30%

Size: around 20 KB, not including the save lists and in-game RAM.

ReplyOptionsI have a factoring program that will solve everything, I just need to type it in.

ReplyOptionsPlease wait.

ReplyOptionsBasically, you need to make sure you get the signs right on the factors.

Given A, B, and C, find N and O so that

N+O=B

NO=AC

ReplyOptionsHere it is: (Works on the TI-83 Plus and up)

:ClrDraw

:AxesOff

:ClrHome

:Horiz //Answer will be displayed on the graph screen

:Prompt A,B,C //Get quadratic

:If not(C

:Then

:{A,B,1,0}→L1

:Goto 2 //"Goto 2" skips to the display command

:End

:If not(A //A=0 means it isn't a quadratic

:Then //but I put it in for the sake of completeness

:{B,C,0,1}

:Goto 2

:End

:abs(AC→P

:1-2(AC<0)→M

:0→Q

:For(N,1,P) //Searches for factors

:Output(4,1,{N,P}) //Lets you know if it will take a while

:P/N→O

:If not(fpart(O

:Then

:1-2(B<0)→R

:R*abs(N+MO)→R //I put in the multiplication sign for readability

:If R=B //If factors found

:Then //End Loop

:N→Q

:P→N

:End

:End

:End

:If not(Q) //If no factors found

:Goto 3

:If Q>0

:Then

:Q→N

:Else

:O→N

:Q→O

:End

:1-2(B<0)→R

:MR→S

:RN→N

:SO→O

:A→X

:N→Y

:X/Y→Z

:While fpart(Z) //Finds GCF of A and N

:X-Yfpart(Z)→(-) //Theta

:Y→X

:(-)→Y

:X/Y→Z

:End

:A/Y→D

:N/Y→E

:Y→F

:O/D→G

:If FD=/=A or FE+GD=/=B or GE=/=C //Not equal to

:Goto 3 //This shouldn't happen

:{D,E,F,G}→L1

:If sum(L1>0)<=1 //Less than or equal to

:-L1→L1 //Makes sure at least two factors are positive

:Lbl 2

:Text(0,0,"(", L1(1), "X", sub("-+", 2-(L1(2)<0),1), abs(L1(2)), ")(", L1(3), sub("-+", 2-(L1(4)<0),1), abs(L1(4)), ")")

:Goto 4 //The long Text( command means the calc doesn't

:Lbl 3 //have to calculate the lengths of numbers.

:Text(0,0,"PRIME")

:Lbl 4

:Pause

:AxesOn

:Full

:ClrHome

:Output(1,1," //Gets rid of the "Done"

Please comment!

ReplyOptionsIt might work on the TI-83 regular, I don't know.

This was programmed on a TI-83 plus, regular edition.

ReplyOptionsPretty sure that

should be

ReplyOptionsThat moves the cursur to the second line, which is not ideal.

ReplyOptionsOh…

ReplyOptionsBy the way, how do you set the code apart from the rest of the text like that?

ReplyOptionsI prefer to use the assembly code to get rid of the done. And Johnny, it is the little box above the gui that says code. I'm not sure if guests can access it or not

live the life because the life is good —vivir la vida, porque la vida es buena

Vie la vie que la vie est bonne quod est bonum vitae in vita

lebe das Leben, weil das Leben ist gut —vivere la vita, perché la vita è buona

ReplyOptionsNo, I don't see it. Thanks anyway.

ReplyOptionsWhat do th a, b and c represent that the program asks for when executed?

ReplyOptionsA(x)^2+B(x)+C

A, B, and C are the constants

live the life because the life is good —vivir la vida, porque la vida es buena

Vie la vie que la vie est bonne quod est bonum vitae in vita

lebe das Leben, weil das Leben ist gut —vivere la vita, perché la vita è buona

ReplyOptionsCan i just write this program in my TI-84 Plus CE, or do i have to download it onto the calculator?

ReplyOptionsYou can just write it.

The Silver Phantom welcomes youReplyOptions