Results 1 to 1 of 1
- 08-24-2008, 04:27 PM #1
[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;
Last edited by Norm; 08-24-2008 at 07:31 PM.
- By matt_well in forum New To JavaReplies: 17Last Post: 08-30-2008, 09:05 PM
- By bilal_ali_java in forum Advanced JavaReplies: 3Last Post: 08-16-2008, 01:11 AM
- By java_fun2007 in forum New To JavaReplies: 2Last Post: 11-26-2007, 07:51 PM
- By Peter in forum New To JavaReplies: 2Last Post: 07-04-2007, 06:15 AM
- By Marcus in forum Advanced JavaReplies: 3Last Post: 07-02-2007, 01:30 PM