Results 1 to 6 of 6

Thread: [RESOLVED] Solving the equation with three unknowns

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Resolved [RESOLVED] Solving the equation with three unknowns

    Hi friends,

    I want to ask a question about a programme will solve the equation with three unknowns.

    I will make a programme will solve these equations. Now, I need to know, how I can make this. I need the idea of making this programme.

    What do you think?



    Thanks..

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Solving the equation with three unknowns

    Please show us a specific example of what you need.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Re: Solving the equation with three unknowns

    For example,

    a+b+c = 7
    3a+5b+9c = 29
    2a+9b+7c =32

    what are the values of a, b and c?

    The programme will solve this

  4. #4
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Solving the equation with three unknowns

    OK, so you are talking about a straightforward system of 3 linear equations and 3 unknowns. Do you know how to solve those values by hand? If not, I recommend reading this handy wikipedia page. In particular, pay attention to the elimination method, which uses Gaussian Elimination.

    Thus, if you place the coefficients of a, b, and c in a matrix (aka two dimensional array), and the solution set in a one-dimensional array, you can perform operations to put the matrix in echelon form. Once that is done, your array will contain the correct values of a, b, and c.

    If you're not sure the proper technique for getting a matrix into echelon form given your language, you can refer to this pseudocode, and then if you still need help, you can post specific questions in the forum for whichever language you are programming in.

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Solving the equation with three unknowns

    It's worth mentioning that many, many languages have linear algebra libraries that should be used for this type of work rather than reinventing the wheel by implementing your own methods--though if this is an exercise in coding rather than "real" work reinventing the wheel is fine.

    On the off chance your problem is restricted to precisely 3 variables and 3 equations, you can actually hard-code the solutions using, for instance, Cramer's Rule, which gives the magical formulas

    Code:
    ax + by + cz = j
    dx + ey + fz = k
    gx + hy + iz = l
    implies

    Code:
    M = a*e*i + b*f*g + c*d*h - c*e*g - b*d*i - a*f*h
    x = (j*e*i + b*f*l + c*k*h - c*e*l - b*k*i - j*f*h) / M
    y = (a*k*i + j*f*g + c*d*l - c*k*g - j*d*i - a*f*l) / M
    z = (a*e*l + b*k*g + j*d*h - j*e*g - b*d*l - a*k*h) / M
    where if M is zero, the system has zero or infinitely many solutions. (For instance, take a=b=...=h=i=0 and j=k=l=0 or j=k=l=1.)

    In the case you gave, this method correctly gives (x, y, z) = (4.25, 2.125, 0.625).
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: [RESOLVED] Solving the equation with three unknowns

    Dang, I forgot about Cramer's rule. Shows you what happens when you become addicted to Mad Money and lose track of the real world.

    Jemidiah, please forgive me for this shortcoming. I could write code for the solution, once the value of the coefficients are trapped within each equation. That's surprisingly easy.
    Doctor Ed

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width