%! % PS LINEAR EQUATION SOLVER FOR N=4 LINEQ04.PS % ============================================ % Copyright c 1999 by Don Lancaster and Synergetics, Box 809, Thatcher, AZ, 85552 % (520) 428-4073 don@tinaja.com http://www.tinaja.com % Consulting services available per http://www.tinaja.com/info01.html % All commercial rights and all electronic media rights fully reserved. % Personal use permitted provided header and entire file remains intact. % Linking is welcome. Reposting expressly forbidden. % This utility demo shows how to use PostScript to solve linear algabraic equations % by use of Gaussian elimination. It is easily extended to higher orders. % Additional details in http://www.tinaja.com/glib/muse142.pdf % This code currently includes temporary test and reporting utils. % temp report utility /aaa {10 string cvs print ( ) print} def /rrr {(\n\n) print w0 aaa x0 aaa y0 aaa z0 aaa ( ) print a0 aaa (\n) print w1 aaa x1 aaa y1 aaa z1 aaa ( ) print a1 aaa (\n) print w2 aaa x2 aaa y2 aaa z2 aaa ( ) print a2 aaa (\n) print w3 aaa x3 aaa y3 aaa z3 aaa ( ) print a3 aaa (\n) print } def % Define or capture your data. To avoid any div0 problems, preplace your largest % absolute values on your principle diagonals... /w0 -3.997 store /x0 2.075 store /y0 -0.997 store /z0 1.436 store /a0 29.223 store /w1 2.345 store /x1 -0.654 store /y1 -8.231 store /z1 1.234 store /a1 -13.491 store /w2 -3.224 store /x2 12.223 store /y2 -1.06 store /z2 4.987 store /a2 1.342 store /w3 0.334 store /x3 -1.653 store /y3 2.724 store /z3 -7.003 store /a3 -13.365 store /solven04 { (\n\nraw equations) == rrr % normalize w0 to unity... /a0 a0 w0 div store /z0 z0 w0 div store /y0 y0 w0 div store /x0 x0 w0 div store /w0 w0 w0 div store % /w0 1.000 store (\n\nforcew0 to unity) == rrr % force w1 to zero... /a1 a1 a0 w1 mul sub store /z1 z1 z0 w1 mul sub store /y1 y1 y0 w1 mul sub store /x1 x1 x0 w1 mul sub store /w1 w1 w0 w1 mul sub store % check % /w1 0 store (\n\nforce w1 to zero)== rrr % normalize x1 to unity... /a1 a1 x1 div store /z1 z1 x1 div store /y1 y1 x1 div store /x1 x1 x1 div store % /x1 1.000 store (\n\nnormalize x1 to zero) == rrr % force w2 to zero /a2 a2 w2 a0 mul sub store /z2 z2 w2 z0 mul sub store /y2 y2 w2 y0 mul sub store /x2 x2 w2 x0 mul sub store /w2 w2 w2 w0 mul sub store % /w2 0 store (\n\nforce w2 to zero) == rrr % force x2 to zero... /a2 a2 a1 x2 mul sub store /z2 z2 z1 x2 mul sub store /y2 y2 y1 x2 mul sub store /x2 x2 x1 x2 mul sub store % /x2 0 store (\n\nforce x2 to zero) == rrr % normalize y2 to unity... /a2 a2 y2 div store /z2 z2 y2 div store /y2 y2 y2 div store % /y2 1.000 store (\n\nnormalize y2 to unity) == rrr % force w3 to zero (w3 - w0/w3) /a3 a3 a0 w3 mul sub store /z3 z3 z0 w3 mul sub store /y3 y3 y0 w3 mul sub store /x3 x3 x0 w3 mul sub store /w3 w3 w0 w3 mul sub store % /w3 0 store (\n\n force w3 to zero) == rrr % force x3 to zero /a3 a3 a1 x3 mul sub store /z3 z3 z1 x3 mul sub store /y3 y3 y1 x3 mul sub store /x3 x3 x1 x3 mul sub store % /x3 0 store (\n\nforce x3 to zero) == rrr % force y3 to zero /a3 a3 a2 y3 mul sub store /z3 z3 z2 y3 mul sub store /y3 y3 y2 y3 mul sub store % /y3 0 store (\n\nforce y3 to zero) == rrr % normalize y3 to unity (solving for z) /z a3 z3 div store % solve for y by back substitution... /y a2 z2 z mul sub store % solve for x by back substitution... /x a1 z1 z mul sub y1 y mul sub store % solve for w by back substitution... /w a0 z0 z mul sub y0 y mul sub x0 x mul sub store % report the results (w = ) print w 10 string cvs print (\n) print (x = ) print x 10 string cvs print (\n) print (y = ) print y 10 string cvs print (\n) print (z = ) print z 10 string cvs print (\n) print % check results {/w0 -3.997 store /x0 2.075 store /y0 -0.997 store /z0 1.436 store /a0 29.223 store /w1 2.345 store /x1 -0.654 store /y1 -8.231 store /z1 1.234 store /a1 -13.491 store /w2 -3.224 store /x2 12.223 store /y2 -1.06 store /z2 4.987 store /a2 1.342 store /w3 0.334 store /x3 -1.653 store /y3 2.724 store /z3 -7.003 store /a3 -13.365 store} -3.997 w mul 2.075 x mul add -0.997 y mul add 1.436 z mul add == 29.223 == 2.345 w mul -0.654 x mul add -8.231 y mul add 1.234 z mul add == -13.491 == -3.224 w mul 12.223 x mul add -1.06 y mul add 4.987 z mul add == 1.342 == 0.334 w mul -1.653 x mul add 2.724 y mul add -7.003 z mul add == -13.365 == } def solven04 glotz % force log % solve the equations %% EOF