
Negative Numbers
Does anyone know how to turn a value into a negative number?
An example:
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.

Code:
x = (b/2)*(a);
if(x>0)
x=x;
LC

Quote:
Originally posted by LynuxPenguin
Code:
x = (b/2)*(a);
if(x>0)
x=x;
LC
Thank you.
After posting this though, I realized that this would work:
PHP Code:
x = b/2 * a;
x2 = x;
x3 = x;
Which does the same, but hey

Been a while since I did quadratics, but isn't the equation
b

2a?
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.

Try:
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
Code:
x = b/(2*a);
if (x > 0)
x = x;

The full quadratic equation is
Code:
x= (b+sqrt((b*b)(4*a*c)))/(2a)
and
x= (bsqrt((b*b)(4*a*c)))/(2a)
You shouldn't need to do what you're doing... because xy 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.