Results 1 to 8 of 8
Thread: Quadratic Expression
 11282009, 05:59 PM #1Member
 Join Date
 Nov 2009
 Posts
 8
 Rep Power
 0
Quadratic Expression
Hi guys,
I have an assignment of Quadratic Expression and my professor wants me to have these methods:
get() and set() for three variables
add(QuadraticExpression) : QuadraticExpression
substract(QuadraticExpression) : QuadraticExpression
getRootOne() : double
getRootTwo() : double
toString() : String
getNumRealRoots() : int
I know how to do all of them except getNumRealRoots() : int
What is this method for? I need help for the logic..
Thanks..:)
 11282009, 06:16 PM #2Member
 Join Date
 Nov 2009
 Posts
 96
 Rep Power
 0
With that name I suppose that he want you to get the roots of the expresion, but I'm surprised that it should return an integer. Are you sure about that? The formula for getting the roots is very simple, the only thing you have to do is compute the solution of the equation a*x^2+b*x+c=0.
roots = [b + sqrt(b^24a*c)]/2*a
As you can see, the real roots can be represented as floats, but not always as integers.

Sky: It's not supposed to return the real roots but to give the count of them. With quadratic equations, that number can be 2, 1, or 0, and is determined by the results of:
(b * b  4 * a*c)
If this is 0, then there is 1 real root, if > 0, then 2 real roots, if < 0, then no real roots (all roots in this situation are complex).Last edited by Fubarable; 11282009 at 06:26 PM.
 11282009, 06:27 PM #4Member
 Join Date
 Nov 2009
 Posts
 96
 Rep Power
 0
Yes, you are right, I just missed the word Num. Well, maybe he can add it as an extra :P
 11282009, 07:03 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,071
 Blog Entries
 7
 Rep Power
 24
Never calculate the roots of a quadratic equation like that; it is numerically instable; better read this link for a numerical more stable method.
kind regards,
Jos
 11282009, 07:05 PM #6Member
 Join Date
 Nov 2009
 Posts
 96
 Rep Power
 0
Thanks for the link, I didn't know that.
 11282009, 07:10 PM #7Member
 Join Date
 Nov 2009
 Posts
 8
 Rep Power
 0
So..
This getNumRealRoots() only checks if the result of Math.sqrt(b^2  4*a*c)?
It is not returning any value that I can use in the calculation of the getRootOne() and getRootTwo()?
Thanks for the expert's help...:)
 11282009, 07:16 PM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,071
 Blog Entries
 7
 Rep Power
 24
Similar Threads

regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10072009, 12:25 PM 
program for a quadratic formula
By bbtgirl in forum New To JavaReplies: 9Last Post: 01302009, 07:06 PM 
Quadratic Equation
By jpnym15 in forum New To JavaReplies: 4Last Post: 11122008, 04:29 AM 
Quadratic GUI
By ryn21 in forum New To JavaReplies: 1Last Post: 10302008, 06:58 AM 
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07252007, 08:23 PM
Bookmarks