home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / fortran / 3457 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.3 KB

  1. Path: sparky!uunet!engcon!ropella
  2. From: ropella@engcon.marshall.ltv.com (GEROPELLA)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Permutation through recursion.
  5. Message-ID: <998@engcon.marshall.ltv.com>
  6. Date: 4 Sep 92 18:57:56 GMT
  7. Reply-To: ropella@engcon.UUCP (GEROPELLA)
  8. Organization: LTV MEG, Dallas, TX
  9. Lines: 65
  10.  
  11.  
  12. The following is a VAX fortran polynomial evaluator.  But,
  13. it only works for up to 3 variables.  What I would like from
  14. ya'll is an algorithm that will evaluate any polynomial in
  15. any number of dimensions for any order.  I feel that recursion
  16. is the only answer and, of course, VAX fortran doesn't have
  17. recursion built in; but I'm really going to implement it on
  18. a DEC station, anyway, and DEC fortran does have recursion.
  19.  
  20. If somebody could tell me how to modify this, or if you have
  21. a better way of doing it (in fortran, though); please post
  22. the algorithm.  (Since our company was just bought, I'm 
  23. afraid our email is getting screwed up.)  Or try to  email
  24. me.
  25.  
  26.  
  27. CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  28. C...
  29.       REAL*4 FUNCTION Poly(X,Eqn,var,order)
  30.       IMPLICIT NONE
  31.       REAL*4  X(4),TFLYOUT,mult,Eqn(*)
  32.       INTEGER var,order,i,j,k,l,numcoef,p,ndx(4)
  33.  
  34.       TFLYOUT = 0.0
  35.       numcoef = 0
  36.       mult    =1.0
  37.  
  38. C  The following loop creates the alpha-index in this order:
  39. C  000,001,002,010,011,020,100,101,110,200
  40. C  where the first digit represents the power of the x variable,
  41. C  the second represents the power of the y variable, and the third
  42. C  represents the power of the z variable in the terms of the polynomial.
  43.  
  44.       do i=0,order
  45.          ndx(1) = i
  46.          do j=0,order-i
  47.             ndx(2) = j
  48.             do k=0,order-i-j
  49.                ndx(3) = k
  50.                mult = 1.0
  51.                numcoef=numcoef+1
  52.                do l=1,var
  53.                   if ((x(l) .eq. 0.0) .and. (ndx(l) .eq. 0)) then
  54.                     continue
  55.                   else 
  56.                     mult=mult*(X(l)**ndx(l))
  57.                   end if
  58.                end do
  59. c                 write(*,*) (ndx(p),p=1,3)
  60. c                 write(*,*) tflyout,' + ',Eqn(numcoef),' * ',mult
  61.                TFLYOUT=TFLYOUT+Eqn(numcoef)*mult
  62.             end do
  63.          end do
  64.       end do
  65.  
  66.       Poly = TFLYOUT
  67.  
  68.       RETURN
  69.       END
  70.  
  71.  
  72. glen e. ropella
  73. ropella@engcon.marshall.ltv.com
  74. ropella@engcon.uucp
  75.  
  76.