• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quadratic formula

matas

Golden Member
Does anyone know the code to solve quadratic formula. Input a, b and c.
Looking simplest code possible
 
Originally posted by: Crusty
result = ((-b + sqrt(b*b - 4*a*c))) / (2 * a)
result2 = ((-b - sqrt(b*b - 4*a*c))) / (2 * a)

Does not work. I get Run-time error '5': Invalid procedure call or argument


ChristianV, programs asks a , b, and c as an input. A program plugs in those numbers in a formula and solves it


More info about program:
Check the discriminate. If it is < 0, then there are no real roots
If = 0, then there is a double root.
What the hell is discriminate?
 
I think you have to use Math.Sqrt() instead of sqrt.

I just wasn't sure which formula you wanted to solve, but as I can see from the solution posted above, you want to solve
a(x^2) + bx + c = 0


as for the discriminant:
you have to check if b^2-4ac <0, because the square root of a value below zero is undefined.
 
The discriminant is (B^2-4AC). Taking the square root of a number below zero yields an imaginary number, and VB6 doesn't handle these.

VB6 also doesn't handle exact answers (e.g. 2*sqrt(2)). Instead you're just going to get an approximate decimal answer.

Do you still want to get decimal approximates? I don't really see the point of that though personally for math purposes.

You could check if the discriminant is less than zero and then add "i" to the square root of the absolute value of the discriminant to signify that the answer is imaginary.
 
He's using VB6 so he doesn't have any of the .NET classes. But VB .NET is probably a better idea for something like this. Not sure if it can handle complex nums or not though.
 
Hey, I just did this although it is for QBASIC.

0 PRINT "Enter a,b and c"
1 SLEEP 1
2 INPUT "A:"; a
3 INPUT "B:"; b
4 INPUT "C:"; c
5 PRINT "X is"; ((-b + ((b * b - 4 * a * c) ^ .5))) / (2 * a)
6 PRINT "and"; ((-b - ((b * b - 4 * a * c) ^ .5))) / (2 * a)

it works i verified it with my trusty ti-84
 
Originally posted by: matas
Originally posted by: Crusty
result = ((-b + sqrt(b*b - 4*a*c))) / (2 * a)
result2 = ((-b - sqrt(b*b - 4*a*c))) / (2 * a)

Does not work. I get Run-time error '5': Invalid procedure call or argument


ChristianV, programs asks a , b, and c as an input. A program plugs in those numbers in a formula and solves it


More info about program:
Check the discriminate. If it is < 0, then there are no real roots
If = 0, then there is a double root.
What the hell is discriminate?

Square root in VB6 is Sqr, not sqrt.

 
Back
Top