Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Function Help
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SucreTeen123




PostPosted: Tue Apr 17, 2012 8:14 am   Post subject: Function Help

Write a function nsolutions that takes in three real variables a, b, and c as parameters and returns the number of solutions that the quadratic equation ax2+bx+c=0 has.

please help!!!!
Sponsor
Sponsor
Sponsor
sponsor
smool




PostPosted: Tue Apr 17, 2012 8:16 am   Post subject: RE:Function Help

Well how would you do it on paper?
Raknarg




PostPosted: Tue Apr 17, 2012 9:56 am   Post subject: RE:Function Help

Exactly as smool said. A question like this can be completed the exact same way you would in math class.
Dreadnought




PostPosted: Tue Apr 17, 2012 1:00 pm   Post subject: RE:Function Help

Are complex solutions allowed? (I'm guessing they aren't because that would seem too easy)

Also, to add to what has been said, make sure your careful with the case where a (and perhaps b) are zero.
evildaddy911




PostPosted: Tue Apr 17, 2012 2:47 pm   Post subject: RE:Function Help

do you know the quadratic formula? use it.
D_homes




PostPosted: Tue Apr 17, 2012 4:40 pm   Post subject: RE:Function Help

You could use the remainder/factor theorem.

x is a factor (solution) if f(x) = 0

To find the values for x where f(x) could possibly equal zero, divide all the factors of 'a' by all the factors of 'c', and plug those values into the equation.

See: http://www.purplemath.com/modules/factrthm.htm
Dreadnought




PostPosted: Tue Apr 17, 2012 5:05 pm   Post subject: Re: Function Help

D_homes wrote:
You could use the remainder/factor theorem.

x is a factor (solution) if f(x) = 0

To find the values for x where f(x) could possibly equal zero, divide all the factors of 'a' by all the factors of 'c', and plug those values into the equation.

He want's to find the number of solutions, not necessarily what they are. Also, we're talking real numbers here, trial and error is not a good idea. For this same reason, factoring is also not possible.

For example, consider x^2 + 0*x - 5. This is a simple polynomial (I'm even using integers), yet trying to get a computer to find the exact values of the solution by trial and error is no walk in the park.

There are easy ways to know how many real solutions exist for a polynomial of at most degree 2.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: