x + x^2=90

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

x + x^2=90

Post by {Nathan} » Thu Jan 25, 2007 5:16 pm

I know that in this case, x is equal to 9, but how would I figure this out mathematically?
Image

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Re: x + x^2=90

Post by seaBiscuit$ » Thu Jan 25, 2007 5:50 pm

{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.
sid6.7 wrote:everytime i see your avatar i want to scream and kill it.... :)

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Thu Jan 25, 2007 8:05 pm

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

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Sat Jan 27, 2007 12:47 pm

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.

Post Reply