DRJ100@PSUVM.BITNET (Daniel R. Jeuch) (11/14/89)
Well, I finally got the Multiple Equation Solver typed into the computer. At first, it seems like a waste of time to write a program that takes N equations, and N unknown variables, and solves the system of equations, especially since the HP28's have matrix division built in... But! (that famous 'but') I always make several algebra mistakes in converting algebraic equations into it's coefficient form, ESPECIALLY if it deals in complex numbers, so the need arises for a way for me to type in equations in any form, and have the calculator do the work for me! Thus the Multiple Complex Equation Solver is born! In order to reduce running time, I have the program create a couple of global variables. One, VARB, you must supply in the very beginning so that the program knows what the series of variables are named. (i.e. X1, X2, X3, or I1, I2, I3, etc.) The program then proceeds to make those variables X1, X2, ... to solve the seperate equations, as well as MX, the coefficient matrix, and CONST, the constant matrix. Then the program used the HP28's matrix division to find the final solutions, and rotates the answers into semi-readable form. Note that this solver DOES take complex equations! Example: Equations: (1/2)(i)X3-X1=-4 X1-X2-X3=0 -2X2-(2+2i)-X3=0 Transformed into HP equations. Program assumes equation=0 HP Stack 4: '(1/2)*i*X3-X1+4' or '(0,.5)*X3-X1+4' 3: 'X1-X2-X3' 2: '-2*X2-(2+2*i)-X3' or '-2*X2-(2,2)-X3' 1: 3 * number of equations * DOIT Result: 1: [[ (1,2) ] * X1 * [ (-3,-4) ] * X2 * [ (4,6) ]] * X3 * DOIT[3CF1] * Starts the program running * << -> neq << 1 neq DUP MXM FOR n n neq DPEQ n neq EQEV NEXT 'CONST/MX' EVAL neq 1 2 ->LIST RDM CLMF >> >> DPEQ[CB3D] * Display the equation we're evaluating * << -> eq n neq << eq "Equation " n ->STR + " of " + neq ->STR + " * NEWLINE * " + eq ->STR + 1 CLLCD DISP >> >> EQEV[A127] * Evaluate one equation's coeff. and const * << -> eq n neq << neq VCLR eq EVAL NEQ DUP eq + 'eq' STO 'CONST(n)' STO 1 neq FOR i neq VCLR 1 i VRMK STO eq EVAL 'MX(n,i)' STO NEXT >> >> MXM[BC08] * Make the raw matricies * << -> n << n 1 ->LIST (0,0) * or change (0,0) to 0 for just real equations * CON 'CONST' STO n n 2 ->LIST (0,0) CON * and change (0,0) to 0 here as well * 'MX' STO >> >> VCLR[C592] * Set the variable to 0 * << 1 SWAP FOR i 0 i VRMK STO NEXT >> VRMK[E315] * Take VARB + number and make 'X1' * << ->STR VARB SWAP + * Anyone happen to know the SYSEVAL to convert * "'" SWAP + "'" + * A string on level one into an algebraic eq? * STR-> >> VARB * The root variable * "X" * or whatever variable you use for X1, X2, etc. * Questions? Suggestions? Send to: ------- | Daniel R. Jeuch (DRJ100@PSUVM) | | | 719 Beaver Hall | ( This space left ) | | University Park, PA 16802 | ( intentionally blank ) | | (814) 862-7041 | |
billw@hpcvra.CV.HP.COM (Bill Wickes) (11/16/89)
Take a look at the program SIMEQ, on page 266 of my book HP-28 Insights, for an alternate approach to this problem. (Notice however that the program needs a minor mod to work with complex coefficients--the TRN in line 21 should be TRN CONJ). I couldn't get your programs to work. At least one problem appears to be you wrote NEQ when you meant neq in EQEV. Fixing that still didn't make the programs work, but I haven't had the strength to track the remaining problems down. Bill Wickes billw@cv.hp.com
DRJ100@PSUVM.BITNET (Daniel R. Jeuch) (11/17/89)
The NEQ in EQEV should be NEG... Sorry about that. Checksum remains the same.