Path: funic!news.funet.fi!sunic!mcsun!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!emory!wuarchive!sdd.hp.com!hp-pcd!hpcvra.cv.hp.com!rnews!hpcvbbs!akcs.wiser1 From: akcs.wiser1@hpcvbbs.UUCP (steven lee wiser) Newsgroups: comp.sys.handhelds Subject: simul.non-linear equations Keywords: hp-48sx,non-linear,equations,multiple Message-ID: <27eb7ecf:2507comp.sys.handhelds@hpcvbbs.UUCP> Date: 23 Mar 91 16:40:07 GMT Lines: 235 Simultaneous Non-Linear Equation Solver: Nonlinear and linear This is a program description that solves simultaneous non-linear equations, similar to the programs like TK-Solver Plus ( sold by Universal Technical Systems, 1220 Rock St. Rockford. Il. 1-800-435- 7887). Of course this is not as powerful as TK, but I think you will be impressed by what the HP-48Sx can do. I have solved up to 10 non-linear equations will this routine. Patience is necessary with your HP-48sx above 10 equations or if the equations are of complicated form. This routine uses the solution developed in the book "Design of Thermal Systems", third edition, by W. R. Stoecker , published by McGraw Hill. The Newton-Raphson Method with multiple equations and unknowns is the mathematical method used. Approximately 1k of memory is used by the basic routines. Additional memory is used for the equations and guess terms. Additionally, linear equations can be easily solved with this system. Usually only one iteration is necessary for the linear system. With this system, the equations can be written in any form or order as is convenient. SIMUL.EQ Name of the directory on my HP-28S or 48SX The following are words in the SIMUL.EQ directory: CONT control program for solving the equations u test for convergence number NEW.G sequence that defines the new guesses of values DIF.F program sequence that takes the partial derivatives EVA.F program sequence to evaluate the primary functions at each iteration guess value. F list of equation names ex. { f1 f2 f3 ...} L list of variable names ex. { x y z ....} CONT << 0 'ITER' STO F SIZE 'A' STO {A 1 } 1 CON { A 1 } 0 CON TMP1' STO 'TMP2' STO DO NEW.G 'ITER' 1 STO+ UNTIL TMP1 TMP2 - ARRY-> DROP A 1 - 1 START + -1 STEP ABS u < END 440 .5 BEEP >> u .1 This value should vary based upon the magnitude of the guess values. Ex. variable guess values of 1000 should indicate that a relative large value for u should be used; for small variable guess values a small value of u should be used. If a large guess and a small guess are both in the problem experience should dictate which is the most important value to govern the control value. NEW.G << 1 A FOR J 'L(J)' EVAL EVAL NEXT { A 1 } ->ARRY 'TMP1' STO 1 A HHHH$$$$JR(J)' EVAL EVAL NEXT { A 1 } ->ARRY DIF.F - ARRY-> DROP A 1 FOR K 'L(K)' EVAL STO -1 STEP 1 A FOR J 'L(J)' EVAL EVAL NEXT { A 1 } ->ARRY 'TMP2' STO >> DIF.F << EVA.F 1 A FOR J 1 A FOR K 'F(J)' EVAL 'L(K)' EVAL d (see d explained below) NEXT NEXT { A A } ->ARRY / >> WHERE ' d ' is the differential symbol in HP-28s and now the HP-48SX. EVA.F << 1 A FOR J 'F(J)' EVAL EVAL EVAL NEXT { A 1 } ->ARRY >> Note: for very complicated equations it may be necessary to experiment with additional numbers of "EVAL" where you see 2 or 3 of them presently. Example of a equation: f1 z = x^2 + y*SIN(x) with variables x , y , z rewrite f1 to be : x^2 + y*sin(x) - z This routine sets up the equations like this: ---------------MATRIX----------------------- / EVAL----- f1 : d(f1)/d(x) d(f1)/d(y) d(f1)/d(z) .... / f1(x,y,z,..) f2 : d(f2)/d(x) d(f2)/d(y) d(f2)/d(z) .... / f2(x,y,z...) f3 : d(f3)/d(x) d(f3)/d(y) d(f3)/d(z) .... / f3(x,y,z...) | | | | | | | | | | | | f1 f2 f3 are initially evaluated at the initial guess values x , y and z.... are solved based on matrix algebra These new values of x, y, and z are then used to evaluate the equations f1, f2, f3 again to achieve a new set of x, y, and z guess values. This continues until the sum of the differences from one f1 to another f1 thru f3... is less than the test value given in the term "u." To review to final answers look at either one of the "temp" matrices oreview the actual variables within the list. Whenever the test value is less than the sum of the differences the routine stops and beeps. This routine can be changed in various ways. One is to beep at each iteration. Another is to send to the screen the values of the variables to indicate how the solution is progressing. Have a good time with it. Steve Wiser Richmond Va I assume no responsiblity for any use of this program whatsoever. Slw Uploadable program follows: %%HP: T(3)A(D)F(.); DIR F { F1 F2 F3 } L { X Y Z } \Gm LLLL CONTROL \