Friday, October 23, 2009

Solving systems of equations on the HP 50G

I've really noticed a lot of confusion solving systems of equations in RPN mode. This tutorial will hopefully assist you with doing this.

The way that you solve systems on the 50G seems a bit awkward. The reason is simple; the 50G is very optimized for speed and ease of programming, but not necessarily user friendliness. If you're a new user of the 50G, this may be a nuisance, but I can assure you that the way that it's set up is very useful for programming and entering calculations quickly.

So, there are a few types of systems you can solve, and each has a slightly different method:

  • Linear systems - Each variable in each equation in the system is raised to a power of exactly one. An example would be:

    $\ x+y+z=6 $
    $\ 2x-y+3z=9 $
    $\ x+3y-3z=-2 $


  • Polynomial systems - Each variable in the system is raised to a power that is a non-negative integer.

    Example:
    $\ x^2+y^2-z=0 $
    $\ x^2+y-z=-2 $
    $\ 2x^2+2y-z=4 $

  • Non-polynomial systems
  • - "Non-polynomial" basically refers to all of those funky non-conformist types of equations that require odd algebraic tricks or can't be solved by conventional substitution or elimination methods. For some of these, you have no choice but to use a calculator or computer, but those are rare.

    Example:

    $\ x^y=z $
    $\ x\cosh(\dfrac{2}{x}+y)^z=4 $
    $\ y\cosh(\dfrac{3}{x}+y)^5=2 $



    So, here's the straight dope on how to solve them:

    For polynomial systems or small linear systems:

    Let's solve the example polynomial system up there:

    $\ x^2+y^2-z=0 $
    $\ x^2+y-z=-2 $
    $\ 2x^2+2y-z=4 $

    Be sure your calculator is in RPN mode, and APPROX in the MODE>CAS menu is unchecked. Start by keying in the first equation in the equation editor, by pressing Right shift (orange button) then EQW (the "O" button).

    Then, press enter. Do the same thing for the other 2 equations; enter the equation, then press enter. It should look like this:

    Now comes the part that most people screw up on. You have to put it into an array or else the solve program won't recognize it. So, since there are 3 equations, enter the number 3:

    Then press [Right Shift] P, to access the catalog (should say CAT above the P button). You get a list of every single command there:

    So, why navigate through the entire catalog to find the function? Because, with this method, you can leave a soft menu up on the bottom (the ones you control with the function keys) and you can get to the →Array function without having to constantly switch back between where →Array is and whatever you're working on. So, in the catalog, press "→" (Right shift, 0) and it should bring you right to it almost. Scroll down a bit and you should see →Array:

    Press OK. Your equations should go into an array. Now, every time you go to "CAT", →Array will be highlighted so you don't have to search for it.

    Now, put your variables to be solved for into an array, by entering 'X' 'Y' and 'Z' on the stack and pressing 3 (since there are 3 items in our array) :
    Then do →Array again in CAT.

    Now, simply go to the S.SLV menu (Left shift, 7) and press the solve button that's all the way on the right. You should get all the solutions on one line. To get each solution on it's own line, press EVAL. The final product should look like this:


    And that's it! This works for any polynomial system that's somewhat small.


    Big Linear Systems:
    If you have a small linear system, use the method listed for polynomials. If it's a big system, you have to use another method.

    If you've had some experience with matrices, this will be pretty easy. I'll use this example system of 5 equations in 5 variables. This is a rather small system, and you could actually solve it with the first method. However, I'll show this method as an example:

    $\ a+b+c+d+e=15 $
    $\ 2a-b+3c+7d-e=32 $
    $\ -a+3b+3c+7d+e=47 $
    $\ a-b-c-d+10e=42 $
    $\ a+\dfrac{b}{2}-c+d+2e=13 $

    As you can see, you have to put all your variables on the left side of the equation and all constants on the right side. Make sure the variables go in the same order for each equation, and remember that order. I chose the order [a b c d e].

    Now, you could solve this by doing RS (Right shift), NUM.SLV (the number 7) and selecting "Solve lin sys...", which is a bit more user friendly, but that doesn't give exact answers and you can't use it in programming. Instead, we'll do the matrix calculations manually.

    Go into the matrix editor by pressing LS then MTRW (next to the letter O). Press the WID buttons to adjust the size of the matrix so you see 5 columns. Then, make sure there is a dot next to the Go with a sideways arrow by pressing F5. This will automatically jump to the next row after inputting a row. Enter this matrix:

    (To enter 1/2, press the quote key)

    Press enter. You should see it on the stack:

    Press the 1/X key to invert the matrix. You should see a bunch of fractions:



    Key in the constants in MTRW:

    ...and press enter. Now, your two matrices are on the stack. Press the multiply key to multiply them together, and you should get this:

    Remember our order of variables earlier? Well, these numbers correspond to that order, so a=1, b=2, c=3, d=4, and e=5.


    Non polynomial systems:


    If you can't solve a system with algebraic substitution or elimination, you need another method; guided guess and check. I say "guided" guess and check because the calculator at least knows how far off each guess is and roughly how far to adjust the guesses to get closer to the solution.

    Here's our system:

    $\ (\dfrac{x}{y})^z=\dfrac{1}{8} $
    $\ \dfrac{2^x}{3^y}=\dfrac{4}{z^4} $
    $\ \dfrac{xy}{z}=-\dfrac{2}{3} $

    Key these in exactly as you would with the polynomial system, by putting them in arrays. You should have this:


    But, there's one more thing to do before we solve it. Since it's guided guess and check, you have to put in an initial guess. I'll go with 1, 1, and 1. Put that into an array:



    ...and now you're ready to solve. Press RS then NUM.SLV (number 7), and find MSLV. It will show the current guesses on the top and the distance from the solution below that. The closer the lower number is to zero, the better the current solution.

    After a while, you should see the solutions:
    Our solutions are x=2, y=4, and z=3. MSLV is as exact as the calculator's precision will allow, which is useful for irrational answers but uses unnecessary time for simple integer solutions like these.

    Alternatively, there is another guess and check solver that you can download, called SolveSys. This is actually quite a bit faster because you can adjust the tolerance of the solutions.

    If you have any questions or comments, feel free to comment.

    6 comments:

    1. how many variables can i solve in a single system of equations ?

      ReplyDelete
      Replies
      1. you can enter a large number of variables, limited only by the amount of ram of your hp50g

        Delete
    2. When I go to S.SLV a menu pop up. Solve is in it, but hen I press it, it does not or. Ho can I put solve in the down bar in the screan?

      ReplyDelete
    3. When I go to S.SLV a menu pop up. Solve is in it, but hen I press it, it does not or. Ho can I put solve in the down bar in the screan?

      ReplyDelete
    4. Thank you so much. I love you, seriously.

      ReplyDelete
    5. This comment has been removed by the author.

      ReplyDelete