I need to factorise an numeric expression using VB.And also to display the two possible values of the expression.
Eg. x^2 +2x+1
Thanks..
Printable View
I need to factorise an numeric expression using VB.And also to display the two possible values of the expression.
Eg. x^2 +2x+1
Thanks..
Found the roots of your expression.
In your case x1=-1 and x2=-1.
the factorsare are the negative values of the roots:
-(-1) = 1
Your factorised expression is (x+1)(x+1)
Pieter
I think what Mo's getting at though is what's the algorithm.
If all the equations to be solved are quadratics as per the example, it's dead simple.
The equation is y= ax^2 + bx + c and then
x1= (-b + (b^2 - 4ac)^.5) / 2a
x2= (-b - (b^2 - 4ac)^.5) / 2a
Simple code will do that arithmetic.
First you should have the code do 2 things...
1) check for a=0 since the equation is then a straight line not a parabola and it's illegal to divide by the 2a if a=0
2) check if the square root term b^2 - 4ac is <0, because if it is there is no real square root and the curve does not cut the x axis.