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

  1. Path: sparky!uunet!usc!wupost!waikato.ac.nz!comp.vuw.ac.nz!windy!lhn!mdlcpgs
  2. Newsgroups: comp.lang.fortran
  3. Subject: Re: Permutation through recursion.
  4. Message-ID: <1992Sep8.134515.8196@lhn.gns.cri.nz>
  5. From: mdlcpgs@lhn.gns.cri.nz (Phil Scadden)
  6. Date: 8 Sep 92 13:45:15 +1200
  7. References: <998@engcon.marshall.ltv.com>
  8. Organization: Institute of Geological and Nuclear Sciences, Lower Hutt, New Zealand
  9. Lines: 66
  10.  
  11. In article <998@engcon.marshall.ltv.com>, ropella@engcon.marshall.ltv.com (GEROPELLA) writes:
  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. > If somebody could tell me how to modify this, or if you have
  20. > a better way of doing it (in fortran, though); please post
  21. > the algorithm.  (Since our company was just bought, I'm 
  22. > afraid our email is getting screwed up.)  Or try to  email
  23. > me.
  24. > CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  25. > C...
  26. >       REAL*4 FUNCTION Poly(X,Eqn,var,order)
  27. >       IMPLICIT NONE
  28. >       REAL*4  X(4),TFLYOUT,mult,Eqn(*)
  29. >       INTEGER var,order,i,j,k,l,numcoef,p,ndx(4)
  30. >       TFLYOUT = 0.0
  31. >       numcoef = 0
  32. >       mult    =1.0
  33. > C  The following loop creates the alpha-index in this order:
  34. > C  000,001,002,010,011,020,100,101,110,200
  35. > C  where the first digit represents the power of the x variable,
  36. > C  the second represents the power of the y variable, and the third
  37. > C  represents the power of the z variable in the terms of the polynomial.
  38. >       do i=0,order
  39. >          ndx(1) = i
  40. >          do j=0,order-i
  41. >             ndx(2) = j
  42. >             do k=0,order-i-j
  43. >                ndx(3) = k
  44. >                mult = 1.0
  45. >                numcoef=numcoef+1
  46. >                do l=1,var
  47. >                   if ((x(l) .eq. 0.0) .and. (ndx(l) .eq. 0)) then
  48. >                     continue
  49. >                   else 
  50. >                     mult=mult*(X(l)**ndx(l))
  51. >                   end if
  52. >                end do
  53. > c                 write(*,*) (ndx(p),p=1,3)
  54. > c                 write(*,*) tflyout,' + ',Eqn(numcoef),' * ',mult
  55. >                TFLYOUT=TFLYOUT+Eqn(numcoef)*mult
  56. >             end do
  57. >          end do
  58. >       end do
  59. >       Poly = TFLYOUT
  60. >       RETURN
  61. >       END
  62. > glen e. ropella
  63. > ropella@engcon.marshall.ltv.com
  64. > ropella@engcon.uucp
  65.