home *** CD-ROM | disk | FTP | other *** search
/ PC Open 13 / pcopen13.iso / Zip / SM34A.ZIP / LIBRARY / LSOLVE.LI < prev    next >
Encoding:
Text File  |  1993-04-11  |  1.8 KB  |  35 lines

  1. # lsolve() solve linear equations
  2. # e.g. solve equations x+y-3=0 and x-y-1=0 for x and y
  3. # lsolve(x+y-3, x-y-1, x,y) gives [x=2,y=1]
  4.  
  5. lsolve(eq1_, eq2_, x_, y_) := if(order(eq1,x)<=1 and order(eq1,
  6.     y)<=1 and order(eq2,x)<=1 and order(eq2,y)<=1,
  7.     block( dd:=coef(eq1,x,1)*coef(eq2,y,1)-coef(eq1,y,1)*coef(eq2,x,1),
  8.   [ x=(coef(eq1,y,1)*coef(coef(eq2,x,0),y,0)-coef(coef(eq1,x,0),y,0)*coef(eq2,y,1))/dd,
  9.     y=-(coef(eq1,x,1)*coef(coef(eq2,x,0),y,0)-coef(coef(eq1,x,0),y,0)*coef(eq2,x,1))/dd ],
  10.       local(dd) ))
  11. lsolve(eq1_, eq2_, eq3_, x_,y_,z_) := if(order(eq1,x)<=1 and order(eq1,
  12.     y)<=1 and order(eq1,z)<=1 and order(eq2,x)<=1 and order(eq2,
  13.     y)<=1 and order(eq2,z)<=1 and order(eq3,x)<=1 and order(eq3,
  14.     y)<=1 and order(eq3,z)<=1,
  15.     block( dd:=coef(eq1,x,1)*coef(eq2,y,1)*coef(eq3,z,1)+coef(eq2,x,
  16.     1)*coef(eq3,y,1)*coef(eq1,z,1)+coef(eq3,x,1)*coef(eq1,y,1)*coef(eq2,z,
  17.     1)-coef(eq1,x,1)*coef(eq3,y,1)*coef(eq2,z,1)-coef(eq2,x,1)*coef(eq1,y,
  18.     1)*coef(eq3,z,1)-coef(eq3,x,1)*coef(eq2,y,1)*coef(eq1,z,1),
  19.     const1:=coef(coef(coef(eq1,x,0),y,0),z,0),
  20.     const2:=coef(coef(coef(eq2,x,0),y,0),z,0),
  21.     const3:=coef(coef(coef(eq3,x,0),y,0),z,0),
  22.     [ x=-(const1*coef(eq2,y,1)*coef(eq3,z,1)+const2*coef(eq3,
  23.     y,1)*coef(eq1,z,1)+const3*coef(eq1,y,1)*coef(eq2,z,
  24.     1)-const1*coef(eq3,y,1)*coef(eq2,z,1)-const2*coef(eq1,y,
  25.     1)*coef(eq3,z,1)-const3*coef(eq2,y,1)*coef(eq1,z,1))/dd,
  26.     y=-(coef(eq1,x,1)*const2*coef(eq3,z,1)+coef(eq2,x,
  27.     1)*const3*coef(eq1,z,1)+coef(eq3,x,1)*const1*coef(eq2,z,
  28.     1)-coef(eq1,x,1)*const3*coef(eq2,z,1)-coef(eq2,x,1)*const1*coef(eq3,
  29.     z,1)-coef(eq3,x,1)*const2*coef(eq1,z,1))/dd,
  30.     z=-(coef(eq1,x,1)*coef(eq2,y,1)*const3+coef(eq2,x,
  31.     1)*coef(eq3,y,1)*const1+coef(eq3,x,1)*coef(eq1,y,1)*const2-coef(eq1,
  32.     x,1)*coef(eq3,y,1)*const2-coef(eq2,x,1)*coef(eq1,y,
  33.     1)*const3-coef(eq3,x,1)*coef(eq2,y,1)*const1)/dd ],
  34.       local(dd,const1,const2,const3) ))
  35.