-
August 24th, 2008, 09:21 AM
#1
[RESOLVED] 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?
For example:
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?
I'm also posting this on http://www.java-forums.org/
Thanks,
Norm
A bit rusty with algebra.
if y = slope*x + intercept & p1 , p2
slope = (p2.y - p1.y) /(double) (p2.x - p1.x);
intercept = p1.y - slope * p1.x;
Last edited by Norm; August 24th, 2008 at 12:28 PM.
Reason: Solved
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|