[SOLVED] Algorithm for solving 2 equations, 2 unknowns
Anyone have an algorithm for solving a simple 2 equations, 2 unknown problem?
How do you do unknowns in an equation? It seems like you need a parser, substituter and reducer.
The equation(s) is y = ax + b (a straight line) where x and y are known for two points on the line. How do you find the values of a & b?
Given the points: pt1= 1,0 and pt2= 3,1
equation1 = 0 = a*1 + b
equation2 = 1 = a*3 + b
How do you write a program to solve for the values of a and b?
Also posted at CodeGuru Forums - Algorithm for solving 2 equations, 2 unknowns
A bit rusty with algebra:
slope = (p2.y - p1.y) /(double) (p2.x - p1.x);
intercept = p1.y - slope * p1.x;