Results 1 to 1 of 1
  1. #1
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default [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?

    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?

    Also posted at CodeGuru Forums - Algorithm for solving 2 equations, 2 unknowns

    Thanks,
    Norm

    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.

Similar Threads

  1. Solving this equations problem in Java
    By matt_well in forum New To Java
    Replies: 17
    Last Post: 08-30-2008, 09:05 PM
  2. Suggestions required for solving a Java problem
    By bilal_ali_java in forum Advanced Java
    Replies: 3
    Last Post: 08-16-2008, 01:11 AM
  3. I need a help in solving this method using vectors
    By java_fun2007 in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 07:51 PM
  4. equations
    By Peter in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:15 AM
  5. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 01:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •