Does anyone know how to turn a value into a negative number?
that would make x be the negative value of b/2a [incase you don't know, it's 1/2 of a quadratic function].
And I know if b/2a comes out negative, the - sign makes it a positive, but I wish to know how to make it negative if it isn't already.
x = -(b/2)*(a);
Originally posted by Lynux-Penguin
x = -(b/2)*(a);
After posting this though, I realized that this would work:
Which does the same, but hey
x = -b/2 * a;
x2 = x;
x3 = -x;
Been a while since I did quadratics, but isn't the equation
Which is -b/(2a) which is different to (-b/2)*a
In the same way that
(1/2) * 3 = 3/2
1/(2*3) = 1/6
are different. Just thought I'd mention it.
And quantrizi, your way gives you a positive and negative of the answer, and you can't be sure which is in which unless you test. Lynux Penguins way was better because x will always be negative, like you wanted.
BTW, -b/2a, is that the vertex? Just trying to remember.
x = -abs(b/2(a))
Interesting, I hope someone can answer your question Stovellp.
Yeah I'm pretty sure -b/2a is the X position of the vertex (highest or lowest pt) on the quadratic. Why do you want the negative version of it Quantrizi?
I still prefer
x = -b/(2*a);
if (x > 0)
x = -x;
The full quadratic equation is
You shouldn't need to do what you're doing... because x-y for negative y is the same as x+|y| where |n| is the absolute value of n.
Normally thats used to find the X intercepts of the quadratic. The
Part of your equation is the discriminant, if thats negative there are no intercepts (theres no REAL square root of a negative number), if its 0 there is only one interecpt (that is, it touches the X axis), and if its greater than 0 there are two intercepts.
You have the equation twice, one with + one with -. If the discriminant is 0 can you see there will only be one answer, +0 and -0 are the same. If the discriminant is < 0 both equations are invalid (unless we use an imaginary number system), and >0 there will be 2 different answers.
The equation he asked for, -b/2a, is often used to calculate the vertex.