Page 1 of 1

x + x^2=90

Posted: Thu Jan 25, 2007 5:16 pm
by {Nathan}
I know that in this case, x is equal to 9, but how would I figure this out mathematically?

Re: x + x^2=90

Posted: Thu Jan 25, 2007 5:50 pm
by seaBiscuit$
{Nathan} wrote:I know that in this case, x is equal to 9, but how would I figure this out mathematically?
Looks like you have a quadratic equation thingy.

x^2 + x - 90 = 0

Image

though that could be optimized a bit because 'a' and 'b' would be ones.

Posted: Thu Jan 25, 2007 8:05 pm
by moneo
Nathan, I don't remember how to solve it either, but I don't thing the quadratic equation is going to help.

Yoo could use the brute force approach by writing a little program that uses a FOR loop on X, and keeps testing until it finds it. Something like this:
[code}
FOR X = 1 TO 90
T = X + X^2
IF T = 90 THEN PRINT "ANSWER = ";X : GOTIT=1 :EXIT FOR
NEXT X
IF GOTIT=0 THEN PRINT "NOT FOUND, X MUST BE FRACTIONAL"
[/code]

PS, I haven't tried it.

Regards..... Moneo

Posted: Sat Jan 27, 2007 12:47 pm
by Patz QuickBASIC Creations
Yes, I think the quadratic formula would be the best way to solve it, since it works for ANY quadratic.

Code: Select all

PosX=(-B+SQR((B^2)-(4*A*C)))/(2*A)
NegX=(-B-SQR((B^2)-(4*A*C)))/(2*A)
as the quadratic formula has a plus and minus. However, if the discriminant (B^2-4AC) is negative, QB will generate an error because it has an imaginary solution.